invalid functional descriptor - method is generic
Brian Goetz
brian.goetz at oracle.com
Thu Nov 8 05:52:47 PST 2012
Functional interfaces may be generic. The problem is, there is no
syntax for introducing a type parameter into a lambda, and it was deemed
not to be a significant enough concern to introduce yet more syntax.
(There would need to be something as part of the lambda to hold the
introduction of the type parameters <U,W>.) We felt that the syntactic
intrusion for Java 8 was big enough that introducing additional new
syntax for corner cases like this was not warranted.
Generic methods can be converted to generic functional interfaces as
method refs:
GenericFunctionalIntf g = SomeClass::someGenericMethod;
On 11/8/2012 8:32 AM, Olexandr Demura wrote:
> Could you please explain motivation behind restriction on generic methods
> yo not being able to use define functional interface as SAM?
>
> I tried to expose java.util.Mapping as functional interface thru CPS,
> but it happened to not work - errors on both `Both` definitions.
>
> java: incompatible types: invalid functional descriptor: method
> <U>fold(lamb.da.data.bi.Combiner<K,V,U>) in interface lamb.da.data.bi.Both
> is generic.
>
> public interface Both<K, V> extends Mapping<K, V>, BiFunctee<K, V> {
> <U> U fold(Combiner<K, V, U> c);
>
> @Override
> K getKey() default { return fold((k, v) -> k); }
>
> @Override
> V getValue() default { return fold((k, v) -> v); }
>
> @Override
> <U, W> Both<U, W> map(
> Mapper<? super K, ? extends U> m,
> Mapper<? super V, ? extends W> n
> ) default {
> Both<K, V> this0 = this;
> return c -> this0.fold(c.precombine(m, n));
> }
>
> @Override
> Both<V, K> swap() default {
> final Both<K, V> this0 = this;
> return (m) -> this0.fold((K k, V v) -> m.combine(v, k));
> }
>
> }
>
> openjdk version "1.8.0-ea"
> OpenJDK Runtime Environment (build
> 1.8.0-ea-lambda-nightly-h1669-20121030-b63-b00)
> OpenJDK 64-Bit Server VM (build 25.0-b05, mixed mode)
>
> Note, I code that for fun, not for highly loaded production system;
> none of which supports lambdas anyway since java8 is a toy yet.
>
More information about the lambda-dev
mailing list