我有以下结构: public interface BarReturn {} public interface FooReturn {} public interface FooBarReturn extends FooReturn, BarReturn {} public interface Foo { FooReturn fooBar( ); } public interface Bar { BarReturn fooBar(); } public interface FooBar extends Foo, Bar { FooBarReturn fooBar(); } Javac失败并显示以下消息: FooBar.java:2: types Bar and Foo are incompatible; both define fooBar(), but with unrelated […]
从Java 5开始,我们可以使用协变返回类型 。 为什么Java API不利用这个? 以Graphics2D.create()为例。 为什么不重写返回Graphics2D对象? 在我看来,它在所有情况下都是向后兼容的。