我最初有一个界面如下.
public interface testMe {
public Set<String> doSomething();
}
public class A implements testMe {
public Set<String> doSomething() {
return // Set<String>
}
}
Run Code Online (Sandbox Code Playgroud)
我有类似的类实现testMe.现在我必须再添加一个返回的类Set<Some Object>
public class X implements testMe() {
public Set<Some OBject> doSomething() {
}
}
Run Code Online (Sandbox Code Playgroud)
如何在不破坏现有类的情况下在界面中添加此方法?
您可以使用
public interface testMe {
public Set<?> doSomething();
}
Run Code Online (Sandbox Code Playgroud)
要么
public interface testMe {
public Set<? extends CommonSuperclass> doSomething();
}
Run Code Online (Sandbox Code Playgroud)