About java final access modifier -


this question has answer here:

i making java swing application. made check box item, when calling show.isselected() method, got error have make show final, made final , error gone, error in 9th line, did not understand reason making show final , final show ?

    final jcheckboxmenuitem show=new jcheckboxmenuitem("show");     show.setselected(true);     show.addactionlistener(new actionlistener(){          public void actionperformed(actionevent arg0)          {              formpanel.setvisible(show.isselected()); ////// giving error without final          }      }); 

the final keyword prevents reassigning reference show compiler can safely copy value new anonymous object created new actionlistener statement.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -