Skip to content

Instantly share code, notes, and snippets.

@okkero
Last active March 22, 2018 16:38
Show Gist options
  • Save okkero/c22f5d5b2cb7935952dc2d23145ee1e3 to your computer and use it in GitHub Desktop.
Save okkero/c22f5d5b2cb7935952dc2d23145ee1e3 to your computer and use it in GitHub Desktop.
Java 10 type inference bug: inference fails on list of objects of two different classes derived from the same base class, implementing the same interface. Error:java: java.lang.AssertionError: Unexpected intersection type: com.okkero.Test.Super&com.okkero.Test.Foo
public class Test {
interface Foo {}
static abstract class Super {}
static class Sub1 extends Super implements Foo {}
static class Sub2 extends Super implements Foo {}
public static void main(String[] args) {
var b = List.of(new Sub1(), new Sub2());
b.forEach(System.out::println);
}
}
@okkero
Copy link
Author

okkero commented Mar 22, 2018

Does not happen if they extend two different base classes or don't implement any common interfaces

@kabutz
Copy link

kabutz commented Mar 22, 2018

Seems to work with javac. Could this be an Eclipse bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment