List 是个接口,不能new List<?>(),
可以实例List的实现类例如ArrayList,
给List类型的集合添加集合元素是采用add方法,
C.add(参数); 参数是要放进集合中的对象。
List<?> qm= new ArrayList<String>() {
{
this.add("One");
this.add("Two");
this.add("Three");
}
{
this.add("four");
this.add("five");
this.add("six");
}
};
System.out.println(qm);
结果:
直接new List<>()报错如下图: