James Ervin

Greenhorn
+ Follow
since Aug 18, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by James Ervin

Mike Simmons wrote:

Siegfried Heintze wrote:I don't understand how that "as ActionListener" works when we only give it one function.


Well, ActionListener only has one method, so I guess Groovy translates the one code block into an ActionListener implementation that uses the code block as the implementation of the one method. If ActionListener had more than one method, this probably wouldn't work.

I'm not really a Groovy programmer though, so maybe it would be better to ask these questions in the CodeRanch Groovy forum. Or perhaps some nice moderator-type will move the thread over there for you.



I'm the Groovy Oriented Co-worker and what Mike describes is essentially true.

In the case where you have an interface that has more than one method you can do the following. You would take a map with the keys as the method names, the values as a closure representing the method body and then use the 'as' operator to coerce it into the appropriate interface. This method is really cool for quick stubbing in tests.
11 years ago