当然OOP的答案是,
A是
B。如果
A不是一个
B,
A则仅应
B使用
B的功能来构成自己。
大概
B也有一些通用的实现,它们利用了对通用类型的限制。
另一个用例是
B看起来像这样:
abstract class B<T extends B<T>> { public T createCopy(T t);}现在,子类可以实现,
createCopy并且客户端代码可以安全地使用它,而无需强制转换…例如
class A extends B<A> { public A createCopy(A t) { return new A(t); //copy constructor }}比较以上内容:
abstract class B { public B createCopy(B t);}class A extends B { public B createCopy(B t) { //Is the copy an A or a different subtype of B? We don't know. return new A(t); //copy constructor }}


