<分区>
Possible Duplicate:
Overriding return type in extended interface - Bad idea?
让我们考虑以下接口(interface),
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";
}
}
当我需要从类中获取引用时,这是一个很好的做法吗?