A DESCRIPTION OF THE PROBLEM :
Wrong type inference in the presence of a generic with bound to Double and use of ternary operator.
javac rejects the following program when it should accept it.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
java Test.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compile
ACTUAL -
Test.java:7: error: incompatible types: double cannot be converted to T
return v;
^
where T is a type-variable:
T extends Double declared in class Test
1 error
---------- BEGIN SOURCE ----------
class Test<T extends Double, K extends T> {
public T test() {
T foo = (T) null;
final var v = ((true) ?
foo :
(K) null);
return v;
}
}
---------- END SOURCE ----------
FREQUENCY : always
Wrong type inference in the presence of a generic with bound to Double and use of ternary operator.
javac rejects the following program when it should accept it.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
java Test.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compile
ACTUAL -
Test.java:7: error: incompatible types: double cannot be converted to T
return v;
^
where T is a type-variable:
T extends Double declared in class Test
1 error
---------- BEGIN SOURCE ----------
class Test<T extends Double, K extends T> {
public T test() {
T foo = (T) null;
final var v = ((true) ?
foo :
(K) null);
return v;
}
}
---------- END SOURCE ----------
FREQUENCY : always
- relates to
-
JDK-8269386 Imprecise type inference in the presence of ternary operator and wildcard
- Closed
-
JDK-8269737 Wrong Type-Argument inference in presence of bounds and use-site variance
- Closed