-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
11, 17, 18
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
The following example does not compile. If we explicitly define the type of variable x, then it works.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Cls.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compile successfully
ACTUAL -
Cls.java:23: error: incompatible types: Cls4<CAP#1> cannot be converted to Cls4<? extends Cls3<Float>>
return x;
^
where CAP#1 is a fresh type-variable:
CAP#1 extends Cls3<? super Float> from capture of ?
1 error
---------- BEGIN SOURCE ----------
abstract class Cls<T1> {
public Cls() {}
}
abstract class Cls2<T2> extends Cls<T2> {
public Cls2() {}
}
abstract class Cls3<T3 extends Float> extends Cls2<T3> {
public Cls3() {}
}
abstract class Cls4<T4 extends Cls3<? super Float>> {
public Cls4() {}
}
final class Cls5 {
public Cls5() {}
public final Cls4<? extends Cls3<Float>> foo() {
Cls4<? extends Cls3<Float>> y = (Cls4<? extends Cls3<Float>>) null;
var x = y;
// Cls4<? extends Cls3<Float>> x = y; // This works
return x;
}
}
---------- END SOURCE ----------
FREQUENCY : always
The following example does not compile. If we explicitly define the type of variable x, then it works.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Cls.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compile successfully
ACTUAL -
Cls.java:23: error: incompatible types: Cls4<CAP#1> cannot be converted to Cls4<? extends Cls3<Float>>
return x;
^
where CAP#1 is a fresh type-variable:
CAP#1 extends Cls3<? super Float> from capture of ?
1 error
---------- BEGIN SOURCE ----------
abstract class Cls<T1> {
public Cls() {}
}
abstract class Cls2<T2> extends Cls<T2> {
public Cls2() {}
}
abstract class Cls3<T3 extends Float> extends Cls2<T3> {
public Cls3() {}
}
abstract class Cls4<T4 extends Cls3<? super Float>> {
public Cls4() {}
}
final class Cls5 {
public Cls5() {}
public final Cls4<? extends Cls3<Float>> foo() {
Cls4<? extends Cls3<Float>> y = (Cls4<? extends Cls3<Float>>) null;
var x = y;
// Cls4<? extends Cls3<Float>> x = y; // This works
return x;
}
}
---------- END SOURCE ----------
FREQUENCY : always
- relates to
-
JDK-8269348 Wrong type inference in presence of a generic with bound to Double
-
- Closed
-
-
JDK-8269386 Imprecise type inference in the presence of ternary operator and wildcard
-
- Closed
-