我已閱讀有關generics get and put rule應該阻止你加入Banana到List<? extends Fruit>: public abstract class Fruit { }
public class Banana extends Fruit { }
public class Apple extends Fruit { }
List<? extends Fruit>
作爲followup to this question,是否可以編寫一個方法,將Dog添加到合適的房間? (在這個例子中,它會接受一個Animal房間或一個Dog房間。)或者我被迫寫下兩個不同的方法,如下所示? (由於類型擦除,我甚至不能依靠超載)。 public class Rooms {
interface Animal {}
class Dog implements An
,我有以下的代碼: public interface Segment<T> extends Period { ... };
public class SegmentImpl_v1<T> implements Segment<T> { ... };
public interface TimeLine<T, S extends Segment<T>> { ... };
public cl
給這個代碼片斷 //Creates a list of List numbers
List<List<Number>> num = new ArrayList<List<Number>>();
//Creates a list of List doubles
List<List<Double>> doub = new ArrayList<List<Double>>()