-
Bug
-
Resolution: Fixed
-
P3
-
None
-
Verified
Result expressions in lambda bodies are required to be _assignable_ to the targeted return type. For a constant expression, this may involve a narrowing primitive conversion.
If the lambda expression is an invocation argument, and the target type mentions an inference variable, the current spec text requires _invocation compatibility_, which does not allow a narrowing primitive conversion.
Example:
interface ByteFunction<T> {
byte apply(T arg);
}
<T> void m(ByteFunction<T> f) {}
ByteFunction<String> f = s -> 100; // no error
m(s -> 100); // expected: no error; specified: error
javac already seems to behave correctly here.
If the lambda expression is an invocation argument, and the target type mentions an inference variable, the current spec text requires _invocation compatibility_, which does not allow a narrowing primitive conversion.
Example:
interface ByteFunction<T> {
byte apply(T arg);
}
<T> void m(ByteFunction<T> f) {}
ByteFunction<String> f = s -> 100; // no error
m(s -> 100); // expected: no error; specified: error
javac already seems to behave correctly here.