泛型语法:类与原始数据类型 [英] Generics syntax: classes versus primitive data types
本文介绍了泛型语法:类与原始数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么这个不起作用:
ArrayList< LinkedList< int>>
其中:
的ArrayList<链表<整数>>
???
解决方案
因为Java只能使用类
列表<整数>< / code>列表;
这也是为什么有原始类型的包装类的原因:
int - >整数
布尔值 - >布尔
double - > Double
byte - >字节
等...
Why does this one does not work:
ArrayList<LinkedList<int>>
where this one does:
ArrayList<LinkedList<Integer>>
???
解决方案
Because Java can only use classes (and not primitive types) and arrays (also arrays for primitives) for generics (between <
and >
).
List<Integer> list;
That is also a reason why there are wrapper classes for primitive types:
int -> Integer
boolean -> Boolean
double -> Double
byte -> Byte
etc...
这篇关于泛型语法:类与原始数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文