代码里用了HashSet<int>
结果出错,说
Syntax error, insert "Dimensions" to complete ReferenceType
改成HashSet<Integer>才OK
为何?
PHP中文网2017-04-18 10:52:54
The type parameters in generics must be a subclass of Object, so int cannot be used, but the wrapper type Integer of int should be used.
大家讲道理2017-04-18 10:52:54
int is a basic data type, so it won’t work; you should use its corresponding packaging class, Interger
ringa_lee2017-04-18 10:52:54
Simply put, because int is a basic type and does not contain the methods required in the collection framework. Take this as an example. Even hashCode is not implemented. How to calculate the hash value? So you need to use Integer.
The types in generics must be subclasses of Object.
PHP中文网2017-04-18 10:52:54
int is the data type, and Integer is the packaging class. What should be placed in generics is the object type