假设我们有以下接口:
interface Addable { Addable add (Addable element); }
现在我想声明两个类,例如MyList和MyArray实现上述接口。我怎样才能做到这一点,但又防止将MyArray对象添加到 a 中MyList,反之亦然?
MyList
MyArray
if有没有办法在没有声明的情况下做到这一点instanceof?
if
instanceof
java generics interface
generics ×1
interface ×1
java ×1