Possible Duplicate:
Why don't Generics support primitive types?
Why we cannot use double
as a T
, instead we have to use Double?
we will have compile error if using List
Possible Duplicate:
Why don't Generics support primitive types?
Why we cannot use double
as a T
, instead we have to use Double?
we will have compile error if using List
double is not an Object,You can use Double
double
is primitive data type
of Java, while Generics type needs an java.lang.Object
, and Double
is an Object
T must be non-primitive data type. It may seem inconvenient at first glance, but there is auto-boxing, that is you can have something like this:
List<Double> list = new ArrayList<Double>();
double x = 5.0d;
list.add(x);
double y = list.get(0);