, .
, ConcreteCollection ( MyCollectionInterface) updateObject MyObjectInterface<T> ( T extends Number) - , ( ).
, MyCollectionInterface<?> , , ClientClass ", , :
new ClientClass(new ConcreteCollection<Integer>());
, updateObject MyCollectionInterface<Integer>.
foo MyObjectInterface<?> updateObject, , ( Integer , Double , Number), - .
, MyCollectionInterface<?>, updateObject. , :
1) :
private MyCollectionInterface<Number> collection;
public ClientClass(MyCollectionInterface<Number> collection){
this.collection = collection;
}
public void foo(MyObjectInterface<Number> o){
this.collection.updateObject(o);
}
, ( ), :
2) , :
public interface MyCollectionInterface<T extends Number> {
public void updateObject(MyObjectInterface<? extends Number> o);
}
public class ConcreteCollection<T extends Number> implements MyCollectionInterface<T> {
List<MyObjectInterface<T>> list;
public void updateObject(MyObjectInterface<? extends Number> o) {}
}
private MyCollectionInterface<?> collection;
public ClientClass(MyCollectionInterface<?> collection){
this.collection = collection;
}
public void foo(MyObjectInterface<?> o){
this.collection.updateObject(o);
}
, 2) updateObject, list - ( ArrayList ):
List<MyObjectInterface<? extends Number>> list = new ArrayList<MyObjectInterface<? extends Number>>();
<T extends Number> MyCollectionInterface ConcreteCollection, T .
@ :
1) ,
2)
3) , , , .
, , .