在Java中是否可以使用原始类型(int)作为泛型? [英] Is it possible to use a primitive type (int) in as a generic type in Java?

查看:191
本文介绍了在Java中是否可以使用原始类型(int)作为泛型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体来说,使用 SortedMap< Vector< String> ;, int> 我得到在此之后预期的维度( int )令牌。帮助!

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

推荐答案

不,这是不可能的。改为使用整数。自动装箱功能负责其余部分(即,对于大多数目的,您可以编程,就像实际使用 int 一样,因为Java可以转换为整数自动为你)。

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

这篇关于在Java中是否可以使用原始类型(int)作为泛型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆