Community
Participate
Working Groups
This is a follow-up to a Forum post[1]. I have the following interfaces: public interface Bar1 { String getSomething(); } public interface Bar2 extends Bar1 { String getSomethingElse(); } public interface Bar3 extends Bar2 { String getAnotherThing(); } public interface Foo1 { <T extends Bar1> Iterable<T> bars(); } public interface Foo2 extends Foo1 { <T extends Bar2> Iterable<T> bars(); } public interface Foo3 extends Foo2 { Iterable<Bar3> bars(); // <<< compiler warning } There several confusing things. The only complaint the compiler has about with these declarations is a warning about Foo3.bars(): Type safety: The return type Iterable<Bar3> for bars() from the type Foo3 needs unchecked conversion to conform to Iterable<Bar2> from the type Foo2 It seems like the definition of bars() in both Foo2 and Foo3 should be disallowed; but maybe I don't understand the subtleties of generics. Anyway, given that the compiler doesn't seem to have any problems with these definitions, it's even more confusing that has a problem with the following code that tries to use these interfaces: public void test1(Foo2 foo) { for (Bar2 bar : foo.bars()) { // <<< compiler error System.out.println(bar); } } The compiler finds the call to Foo2.bars() "ambiguous": The method bars() is ambiguous for the type Foo2 I don't see how a call to a method with no parameters and no multiple inheritance can be "ambiguous". Then, even further confusing, is that following code compiles *without* complaint: public void test2(Foo3 foo) { for (Bar3 subBar : foo.bars()) { System.out.println(subBar); } } So, a call to Foo2.bars() is "ambiguous", but a call to Foo3.bars() is not? Now I'm really confused. Either I don't understand generics (which is entirely possible, since I tend to rely on the compiler to expose my ignorance) or there is some sort of compiler bug here. [1] http://www.eclipse.org/forums/index.php?t=msg&th=199004
I'll look into this.
What is your build ID ? Did you check what is the behavior with the latest (JDK7 stream) javac ?
(In reply to comment #2) > What is your build ID ? Build id: I20100921-1024 > Did you check what is the behavior with the latest (JDK7 stream) > javac ? No.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.