Fun with method references

Brian Goetz brian.goetz at oracle.com
Wed Aug 4 14:49:26 PDT 2010


Yes, it is our plan to provide a reasonable "starter kit" of SAM interfaces, 
which might include Predicate, Block, Mapper, etc.  (Such a collection will 
never be complete) and to use those in standard APIs where practical (such as 
the suggested Arrays.sortBy example below.)  Details to be determined.

On 8/4/2010 5:45 PM, Paul Benedict wrote:
> Do you think JDK 7 will come with new utility SAM interfaces? I am sure
> there are other common patterns throughout Java that could be SAM-ified.
>
> On Wed, Aug 4, 2010 at 4:33 PM, Brian Goetz <brian.goetz at oracle.com
> <mailto:brian.goetz at oracle.com>> wrote:
>
>     Check this out -- this works with the latest prototype:
>
>     interface Extractor<T, U> {
>          public U get(T t);
>     }
>
>     class Arrays {
>          public <T, U extends Comparable<? super U>>
>          void sortBy(T[] array, Extractor<T, U> extractor) { ... }
>     }
>
>
>     String[] strings = ...
>     Arrays.sortBy(strings, String#length);  // sort strings by length
>
>     Foo[] foos = ...
>     Arrays.sortBy(foos, Foo#getA);          // sort by JavaBean property A
>
>
>
>


More information about the lambda-dev mailing list