Fun with method references
Rémi Forax
forax at univ-mlv.fr
Wed Aug 4 15:16:52 PDT 2010
Le 04/08/2010 23:49, Brian Goetz a écrit :
> 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.
>
If you do that, you will not be able to introduce function type later !
In my opinion, I will be happy if
1) you don't introduce such API now.
2) you introduce them and show how they can be retrofit to use function
type.
I have another fear. The introduction of lambda in C#
has shown that the API to deal with them is really huge.
You need more than a year to have a polished version of such API.
Rémi
> 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