arrays - java parentheses around class while storing reference to button -
i in aprocess of learnning java.
i have code java reference:-
public class buttonlist extends applet implements actionlistener { string msg = ""; button blist[] = new button[3]; public void init() { button yes = new button("yes"); button no = new button("no"); button maybe = new button("undecided"); // store references buttons added blist[0] = (button) add(yes); <<<<<<<<<<<<<<<<<<<<<<<<<<<<< here blist[1] = (button) add(no); blist[2] = (button) add(maybe); // register receive action events for(int = 0; < 3; i++) { blist[i].addactionlistener(this); } }
and wonder "(button) add(yes) " stands .
why should blist[] re assigned button if declared button on previous paragraph.
also button whithin parentheses stands here ?
(button) myvar
inserts runtime check myvar
assigned button
compiler can safely assume myvar
is button
. if myvar
not button
@ runtime, exception thrown.
refer explicit casting more information
java arrays button control
No comments:
Post a Comment