FULL PRODUCT VERSION :
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin MacBook-Pro.local 15.0.0 Darwin Kernel Version 15.0.0: Sat Sep 19 15:53:46 PDT 2015; root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
Consider two interfaces (in package "a")
interface I1 {
default void x() {}
}
interface I2 {
default void x() {}
}
Consider also such class with type variable "T":
class A<T extends I1&I2> {
}
Trying to compile it causes:
Main.java:8: error: class INT#1 inherits unrelated defaults for x() from types I1 and I2
class A<T extends I1&I2> {
^
where INT#1 is an intersection type:
INT#1 extends Object,I1,I2
1 error
Why I can not define such type variable?
Why java cares about unrelated defaults in this case?
What such type variable could "break"?
Just for clarification. I can create several classes of the form:
class A1 implements I1, I2 {
public void x() { };
}
class A2 implements I1, I2 {
public void x() { };
}
and so on. Why I can not declare special kind of type variable for such group of classes?
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile source code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Type variables should not care about unrelated defaults inheritance. Code should be compiled.
ACTUAL -
It doesn't compile.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Main.java:8: error: class INT#1 inherits unrelated defaults for x() from types I1 and I2
class A<T extends I1&I2> {
^
where INT#1 is an intersection type:
INT#1 extends Object,I1,I2
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package a;
public class Main {
}
class A<T extends I1&I2> {
}
interface I1 {
default void x() {
}
}
interface I2 {
default void x() {
}
}
class A12 implements I1, I2 {
public void x() { };
}
---------- END SOURCE ----------