jastrachan | 31 Mar 15:24 2005
Picon

[groovy-dev] heads up: method pointer syntax in CVS HEAD

We phased out the 'automatic method pointer' mechanism whereby you 
could access methods as a property as it tended to lead to confusion 
(especially among new users) and folks often hit this feature by 
accident when looking for a property.

So
     System.out.println

no longer creates a method pointer to the 'println' method on 
System.out.

In CVS HEAD now we've a syntax which has a little echo back to C/C++ 
for finding the address of something.
     System.out.&println

will create a method pointer - which acts and feels like a Closure 
object.

So
     def foo = someObject.&someMethod

     // lets pass foo around as if its a closure, then invoke it later on
     foo(1, 2, 3)

This allows us to pass in method pointers to methods which take 
closures.

     list.each( myObject.&doSomething )

or here's a simple way to bind event listeners with methods

     JButton button = new JButton()

     // lets bind an event listener on the button with some method on 
some other object
     button.actionPerformed = someObject.&doExitMethod

James
-------
http://radio.weblogs.com/0112098/


Gmane