London Lambdas Hackday: Existing Code
Brian Goetz
brian.goetz at oracle.com
Wed Jul 4 08:43:44 PDT 2012
>>> People using Guava's predicate library already will have an interface
>>> doing something identical to the Java 8 Predicate. Furthermore they
>>> will be able to
>>
>> to?
>
> hmm, apologies, let's back this sentence up a bit:
>
> Furthermore they already have a large body of predicate instances that
> exist within the guava space. Or that they may be using within their
> own code. These won't be usable with Java 8 predicates because they
> are of a different nominal type.
>
> The only way I could think of addressing this issue was allowing
> implicit type conversions at target typed locations between functional
> interfaces if they have the same structural type. So you'd be able to
> write:
>
> java.util.functions.Predicate<?> TT =
> com.google.common.base.Predicates.alwaysTrue();
We considered this but a conversion from one type to another just
because they are structurally similar (and we have no reason to believe
either came from a lambda) was too much. However, there's a simpler route:
LegacyPredicate p = ...
Predicate pp = p::isTrue;
This lets us scoop out the functionality the same conversion that is
already present, rather than introducing a new one.
More information about the lambda-dev
mailing list