在定义时保持相同的签名,Storage
因为您仍在定义方法find
(而不是使用它):
Storage implements IStorage {
<T extends ICommon> Collection<T> find(String name, boolean isExact) {
//some code
}
}
当您实际调用该泛型方法时,您将指定具体类型参数:
Storage s = new Storage();
s.<IOrganization>find("hello world", true);
T
但是您在泛型方法中引入的参数类型<T extends ICommon>
没有用,因为您在参数列表中没有。
可能是您可能想要的不是通用方法。但是如下:
interface IStorage {
public Collection<? extends ICommon> find(String name, boolean isExact);
}
//and
class Storage implements IStorage {
public Collection<IOrganization> find(String name, boolean isExact) {
//some code
}
}
//or
class Storage implements IStorage {
public Collection<? extends ICommon> find(String name, boolean isExact) {
//some code
}
}