-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
8
javac should be updated to conform to Lambda Spec bug fix JDK-8029306.
The spec failed to account for the possibility that the qualifying type of an unbound method reference might be a wildcard-parameterized type.
The fix is to perform capture conversion on this type (as well as the type that is inferred to fill in type arguments for a raw type).
The following should compile without error:
Function<Optional<?>, Object> f1 = Optional<?>::get;
Function<Optional<Integer>, Number> f2 = Optional<? extends Number>::get;
Function<LinkedList<? extends Integer>, Integer> f3 = Queue::peek;
Current errors (tested b115):
error: incompatible types: invalid method reference
Function<Optional<?>, Object> f1 = Optional<?>::get;
^
method get in class Optional<T> cannot be applied to given types
required: no arguments
found: Optional<?>
reason: actual and formal argument lists differ in length
where T is a type-variable:
T extends Object declared in class Optional
error: incompatible types: invalid method reference
Function<Optional<Integer>, Number> f2 = Optional<? extends Number>::get;
^
method get in class Optional<T> cannot be applied to given types
required: no arguments
found: Optional<Integer>
reason: actual and formal argument lists differ in length
where T is a type-variable:
T extends Object declared in class Optional
AbstractCRef.java:7: error: incompatible types: bad return type in method reference
Function<LinkedList<? extends Integer>, Integer> f3 = Queue::peek;
^
? extends Integer cannot be converted to Integer
The spec failed to account for the possibility that the qualifying type of an unbound method reference might be a wildcard-parameterized type.
The fix is to perform capture conversion on this type (as well as the type that is inferred to fill in type arguments for a raw type).
The following should compile without error:
Function<Optional<?>, Object> f1 = Optional<?>::get;
Function<Optional<Integer>, Number> f2 = Optional<? extends Number>::get;
Function<LinkedList<? extends Integer>, Integer> f3 = Queue::peek;
Current errors (tested b115):
error: incompatible types: invalid method reference
Function<Optional<?>, Object> f1 = Optional<?>::get;
^
method get in class Optional<T> cannot be applied to given types
required: no arguments
found: Optional<?>
reason: actual and formal argument lists differ in length
where T is a type-variable:
T extends Object declared in class Optional
error: incompatible types: invalid method reference
Function<Optional<Integer>, Number> f2 = Optional<? extends Number>::get;
^
method get in class Optional<T> cannot be applied to given types
required: no arguments
found: Optional<Integer>
reason: actual and formal argument lists differ in length
where T is a type-variable:
T extends Object declared in class Optional
AbstractCRef.java:7: error: incompatible types: bad return type in method reference
Function<LinkedList<? extends Integer>, Integer> f3 = Queue::peek;
^
? extends Integer cannot be converted to Integer
- relates to
-
JDK-8029306 Lambda Spec: Capture for method references like Optional<?>::get
-
- Closed
-