Fun with method references

Brian Goetz brian.goetz at oracle.com
Wed Aug 4 14:33:05 PDT 2010


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