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

Alexander picture Alexander · Jan 5, 2009 · Viewed 13.8k times · Source

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

Answer

Konrad Rudolph picture Konrad Rudolph · Jan 5, 2009

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).