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

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

问题描述

特别是,使用 SortedMap, int> 我得到在此 (int) 标记之后预期的尺寸."帮助!

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

推荐答案

不,这是不可能的.使用 Integer 代替.自动装箱处理剩下的事情(即,在大多数情况下,您可以像实际使用 int 一样编程,因为 Java 会自动为您转换为 Integer 和从 Integer 转换).

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天全站免登陆