为什么在java中有每个基本类型的包装器 [英] Why in java is there a wrapper for every primitive type
本文介绍了为什么在java中有每个基本类型的包装器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Number
子类包装原始数字类型(字节
,整数
, Double
, Float
, Long
,以及短
)。
The Number
subclasses wrap primitive numeric types (Byte
, Integer
, Double
, Float
, Long
, and Short
).
他们的目的是什么?
推荐答案
创建了这些包装类,以便有一些方法可以将这些基本类型与各种容器类一起使用,例如 ArrayList
。由于原始类型不能直接强制转换为 Object
引用,它们存储在包装类中以允许它们在 Object $ c的地方使用$ c>引用是必需的。
Those wrapper classes were created so that there was some way to use those primitive types with various container classes like ArrayList
. Since primitive types can't directly be coerced into Object
references, they are stored in wrapper classes to allow them to be used where Object
references are required.
这篇关于为什么在java中有每个基本类型的包装器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文