|
|
Re: ambiguous methods differ only by (generic) return type [message #635214 is a reply to message #634867] |
Tue, 26 October 2010 02:33 |
Brian Vosburgh Messages: 137 Registered: July 2009 |
Senior Member |
|
|
Stephan Herrmann wrote on Sun, 24 October 2010 13:53 | Brian Vosburgh wrote on Sat, 23 October 2010 07:12 | I have the following interfaces:
public interface Bar {
String getSomething();
}
public interface SubBar extends Bar {
String getSomethingElse();
}
public interface Foo {
<T extends Bar> Iterable<T> bars();
}
public interface SubFoo extends Foo {
<T extends SubBar> Iterable<T> bars();
}
I'm not sure whether SubFoo's declaration of bars() should be allowed, but the compiler seems to have no complaint.
|
IMHO it should complain "The return type is incompatible with Foo.bars(int)",
essentially because Iterable<SubBar> is not conform to Iterable<Bar>.
Anyway, the compiler's behavior doesn't seem kosher to me,
so I suggest you file a bug where we can further track this issue.
thanks,
Stephan
PS:
As for your example, may you need this:
public interface Foo {
Iterable<? extends Bar> bars();
}
public interface SubFoo extends Foo {
@Override
Iterable<? extends SubBar> bars();
}
|
I have entered a bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=328669
As to your suggested code: That type of code is helpful in some places but not so much in others. :-) Also, the compiler complains about the @Override annotation:
Multiple markers at this line
- The method bars() of type SubFoo must override a superclass method
- implements Foo.bars
Pretty funny pair of contradicting messages. :-)
Anyway, if I remove the @Override annotation, the new code compiles fine.
Thanks,
Brian
|
|
|
Powered by
FUDForum. Page generated in 0.01877 seconds