Java interfaces and return types

后端 未结 3 1844
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 09:00

Consider I have the following interface:

public interface A { public void b(); }

However I want each of the classes that implement it to ha

3条回答
  •  情书的邮戳
    2020-12-01 09:54

    Since Java supports covariant return types (since Java 1.5), you can do:

    public interface A { public Object b(); }
    

提交回复
热议问题