java - Passing anonymous function to a method, storing it and executing it? -
i need pass function method, storing on variable visible inside class, , lately executing ( without parameters ).
in actionscript 3 :
private var latecall : function; .. function getthelatecall( o : function ) : void { latecall = o; } ... function somefunction() : void { latecall(); }
- is there equal in java ?
no
you can though have alternates, 1 via interface
interface ifunc { void somefunction(); } class func1 implements ifunc { void somefunction(){..} } class func2 implements ifunc { void somefunction(){..} } void getthelatecall(ifunc func) { func.somefunction(); }
so caller instantiate specific ifunc
implementation , pass getthelatecall
. 1 way of doing it..
Comments
Post a Comment