只是想知道这是否是正确的方法。我想构造我的参数化类的实例,其中一个实例变量是泛型类型。下面的代码有效,但我在主方法中收到很多警告“SomeObject 是原始类型。对泛型类型 SomeObject 的引用应该被参数化”。
public class SomeObject<T> {
private String description;
private T value;
public SomeObject(String description, T value) {
this.description = description;
this.value = value;
}
public static void main(String args[]){
List <SomeObject> objectList = new ArrayList<SomeObject>();
objectList.add(new SomeObject("Object 1: ", true));
objectList.add(new SomeObject("Object 2: ", 888.00));
objectList.add(new SomeObject("Object 3: ", "another object"));
objectList.add(new SomeObject("Object 4: ", '4'));
for (SomeObject object : objectList){
System.out.println(object.getDescription() + object.getValue());
}
}
}