可能重复:
在扩展接口中覆盖返回类型 - 坏主意?
让我们考虑以下界面,
public interface Cat{
public Object getCat();//returns any type of object
}
public interface DomesticCatInterface{
public String somethinOnlyRelatedToDomesticCat();
}
public interface WildCatInterface{
public String somethinOnlyRelatedToWildCat();
}
public class DomesticCat implements Cat, DomesticCatInterface{
@Override
public DomesticCat getCat(){
return this;
}
@Override
public String somethinOnlyRelatedToDomesticCat(){
return "something";
}
}
public class WildCat implements Cat, WildCatInterface{
@Override
public WildCat getCat(){
return this;
}
@Override
public String somethinOnlyRelatedToWildCat(){
return "something";
}
}
当我需要从课堂上获得参考时,这是一个很好的做法吗?