method references: type inference, toString()
pholser at gmail.com
Wed Feb 22 06:50:11 PST 2012
Thanks for the prompt response, and for the reminder about the cast.
Eager to see how things shake out with type inference!
On Tue, Feb 21, 2012 at 5:07 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>> 1) Should the usage of Foo::isBar as the predicate fed to
>> PredicateMatcher.matches() compile successfully? I'm hoping not to
>> have to perform the SAM conversion by hand:
>> Predicate<Foo> bar = Foo::isBar;
>> assertThat(new BarredUpFoo(), PredicateMatcher.matches(bar);
> Without answering the question on whether the inference should succeed or
> not (the exact details of type inference are currently in flux), I'll point
> out that there is a less intrusive form of "by hand" that can be used to
> provide the needed additional type info to the compiler -- use a cast to
> provide the target type. This is less intrusive that having to name a local
> assertThat(new BarredUpFoo(),
> PredicateMatcher.matches((Predicate<Foo>) Foo::isBar));
>> 2) Wondering if it wouldn't be too much trouble to have method
>> references respond to toString() with something like "Foo::isBar" or
>> "method isBar on class Foo", instead of, e.g. "Main$1 at a30a4e". It'd
>> make the output of PredicateMatcher.matches() really slick.
> Yes, the details of this are being actively discussed in the EG, and is a
> desirable goal. Lots of details to work out, of course.
More information about the lambda-dev