我想分解两个列表: 首先是一个整数列表。我decare它为:为什么泛型列表的声明有所不同?
List<Integer> ints= Arrays.asList(1,2,3);
它工作正常。
其次是对象列表。我宣布它为:
List<Object> objs= Arrays.asList(1,2.13,"three");
但是它会在我写它时立即给出一个错误。错误是:
Multiple markers at this line
- Type mismatch: cannot convert from List<Object&Comparable<?>&Serializable> to
List<Object>
- Type safety: A generic array of Object&Comparable<?>&Serializable is created for
a varargs parameter
相反,如果我写
List<Object> objs = Arrays.<Object>asList(1,2.13,"three");
它工作正常。
我无法弄清楚原因。
明白了。感谢非常好的解释。如果出现这种混淆,这将是一个适用的金科玉律。 – 2012-03-30 12:29:31