-
Bug
-
Resolution: Unresolved
-
P4
-
9, 10.0.1, 11
ADDITIONAL SYSTEM INFORMATION :
Ubuntu 18.04 LTS
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
A DESCRIPTION OF THE PROBLEM :
First reported here: https://stackoverflow.com/questions/50928300
Type inference for generics has changed between Java8 and Java9/10 breaking special-case usages e.g. of the hamcrest library. Workarounds seem generally possible by providing more type information.
REGRESSION : Last worked in version 8u172
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile given code with javac from Java9/10.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Code compiles as it does in Java8.
ACTUAL -
Code does not compile, type errors like:
Error:(21, 28) java: incompatible types: inference variable U has incompatible bounds
equality constraints: com.Test.B<? super com.Test.D>
upper bounds: com.Test.B<? super capture#1 of ? super com.Test.D>,java.lang.Object
---------- BEGIN SOURCE ----------
class Test1 {
class A<S> { } class B<S> { } class C<S> { } class D { }
<T> A<B<? super T>> foo() { return null; }
<U> C<U> bar(A<U> a1, A<? super U> a2) { return null; }
C<B<? super D>> c = bar(foo(), foo());
}
class Test2 {
class A<S> { } class B<S> { } class C<S> { } class D { }
<T> A<B<? super T>> foo() { return null; }
<U> C<U> bar(A<? super U> a) { return null; }
C<B<? super D>> c = bar(foo());
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Provide more type information such as casting arguments.
FREQUENCY : always
Ubuntu 18.04 LTS
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
A DESCRIPTION OF THE PROBLEM :
First reported here: https://stackoverflow.com/questions/50928300
Type inference for generics has changed between Java8 and Java9/10 breaking special-case usages e.g. of the hamcrest library. Workarounds seem generally possible by providing more type information.
REGRESSION : Last worked in version 8u172
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile given code with javac from Java9/10.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Code compiles as it does in Java8.
ACTUAL -
Code does not compile, type errors like:
Error:(21, 28) java: incompatible types: inference variable U has incompatible bounds
equality constraints: com.Test.B<? super com.Test.D>
upper bounds: com.Test.B<? super capture#1 of ? super com.Test.D>,java.lang.Object
---------- BEGIN SOURCE ----------
class Test1 {
class A<S> { } class B<S> { } class C<S> { } class D { }
<T> A<B<? super T>> foo() { return null; }
<U> C<U> bar(A<U> a1, A<? super U> a2) { return null; }
C<B<? super D>> c = bar(foo(), foo());
}
class Test2 {
class A<S> { } class B<S> { } class C<S> { } class D { }
<T> A<B<? super T>> foo() { return null; }
<U> C<U> bar(A<? super U> a) { return null; }
C<B<? super D>> c = bar(foo());
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Provide more type information such as casting arguments.
FREQUENCY : always
- duplicates
-
JDK-8326486 Something wrong with type inference.
- Closed
-
JDK-8315134 javac inference seems to be capturing types incorrectly
- Closed
- is blocked by
-
JDK-8016196 Inference: define supertype parameterization for wildcard-parameterized types
- Open