JDK-8146964 : Unrelated defaults inheritance error for type variables
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: x86
  • Submitted: 2016-01-06
  • Updated: 2016-03-02
  • Resolved: 2016-03-02
Related Reports
Duplicate :  
Description
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 ----------


Comments
While I think the whole area is underspecified, I believe that javac is morally correct; you can't have a class that inherits two sibling default methods w/o overriding them, as overload resolution would then be ambiguous/non-deterministic.
13-01-2016

This is an issue, Below error prompts on command prompt. Eclipse compiles the code properly. 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 Issue observed in below versions of Java 9 ea b-96 - Fail 8uxx - Fail (All versions of 8u) 7uxx - NA
13-01-2016