Use of Anonymous Inner Class in java -
public samplebehaviour otherway(final string st) { return new samplebehaviour() { private string str = st; @override public void print() { system.out.println("val:"+val); } }; }
samplebehaviour
interface.
classes implements interface must define methods behavior, whats use of variables in interface?
why method parameter need final? don't real time application type of usage? what's real thing behind this?
if it's useful, why doesn't c++ have this?
from the java language specification, section 8.1.3:
any local variable, formal parameter, or exception parameter used not declared in inner class must declared final.
wikipedia says it's inner class needs keep own copy of variable since can live on after outer class goes out of scope; prevent having same variable name refer 2 different locations, forced variable fixed in place.
Comments
Post a Comment