Alexander
Alexander

Reputation: 976

Is it possible to use a primitive type (int) in as a generic type in Java?

Specifically, with a SortedMap<Vector<String>, int> I get "dimensions expected after this (int) token." Help!

Upvotes: 25

Views: 14025

Answers (2)

Craig P. Motlin
Craig P. Motlin

Reputation: 26758

Konrad is correct. Alternately, you can use the trove class TObjectIntHashMap to map Objects to primitive ints.

Upvotes: 3

Konrad Rudolph
Konrad Rudolph

Reputation: 546213

No, this is not possible. Use Integer instead. Autoboxing takes care of the rest (i.e. for most purposes you can program as if you had actually used int because Java converts to and from Integer automatically for you).

Upvotes: 35

Related Questions