groovy

Allow conversion from closure to interface

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.0-RC-1
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    1

Description

It is relatively easy to adapt a closure to a one-method interface. And such conversion should be very useful for implementing functors from within groovy.

syntax can be:

{a->a.name=="a"} as Predicate

The attached class is a dynamic proxy that implements this adapter functionality. It is currently used in a category class to enable a syntax like "Predicate.impl {...}".

Just hook it up to the "as" keyword should make it work.

Activity

Hide
blackdrag blackdrag added a comment -

I applied a modified version of the patch and added a test

Show
blackdrag blackdrag added a comment - I applied a modified version of the patch and added a test

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: