Consider this Java program:
public class IntersectionBug {
public static interface FooInterface {
public void foo();
}
public static class FooSupport {
protected void foo() {
}
}
public static class Whatever<T extends FooSupport & FooInterface> {
}
}
It fails to compile under JDK 1.8 compiler:
$ javac IntersectionBug.java
IntersectionBug.java:12: error: foo() in FooSupport cannot implement foo() in FooInterface
public static class Whatever<T extends FooSupport & FooInterface> {
^
attempting to assign weaker access privileges; was public
1 error
Obviously, if some type T
is both a FooSupport
and a FooInterface
, then it must have a public void foo()
, so the error is bogus.
My question: is this a compiler bug, or does the JLS really specify that this program is invalid? If the latter is the case, why the sub-optimal JLS behavior here?