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

前端 未结 2 610
陌清茗
陌清茗 2020-11-30 13:23

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

相关标签:
2条回答
  • 2020-11-30 14:12

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

    0 讨论(0)
  • 2020-11-30 14:23

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

    0 讨论(0)
提交回复
热议问题