0

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

Community
  • 1
  • 1
user705414
  • 20,472
  • 39
  • 112
  • 155

4 Answers4

1

Generics type parameter must be a sub-class of java.lang.Object.

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
1

double is not an Object,You can use Double

刘伟科
  • 432
  • 3
  • 12
0

double is primitive data type of Java, while Generics type needs an java.lang.Object, and Double is an Object

Quincy
  • 4,393
  • 3
  • 26
  • 40
0

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);
Tair
  • 3,779
  • 2
  • 20
  • 33
  • As with @LiuwkCn's answer: this does not answer the question at all. It states the "what" (which the OP appears to have already figured out), not the "why." -1 – Matt Ball Oct 14 '11 at 03:29