Integer.class 与 int.class [英] Integer.class vs int.class
问题描述
Integer.class
、Integer.TYPE
和 int.class
有什么区别?
What is the difference between Integer.class
, Integer.TYPE
and int.class
?
告诉我
Integer.class
是 Integer (Wrapper) Class 对象的引用- 但是什么是
int.class
作为int
不是一个类,它是一个原始类型.Integer.TYPE
指的是什么?
Integer.class
is a reference of Integer (Wrapper) Class object- but what is then
int.class
asint
is not a class, it's a primitive type. And what doesInteger.TYPE
refer to?
推荐答案
来自 java.lang.Class.isPrimitive
API
有九个预定义的 Class 对象来表示八种原始类型和 void.它们由 Java 虚拟机创建,并与它们所代表的原始类型具有相同的名称,即 boolean、byte、char、short、int、long、float 和 double.
There are nine predefined Class objects to represent the eight primitive types and void. These are created by the Java Virtual Machine, and have the same names as the primitive types that they represent, namely boolean, byte, char, short, int, long, float, and double.
这些对象只能通过以下公共静态最终变量java.lang.Boolean.TYPE
、java.lang.Integer.TYPE
等访问
These objects may only be accessed via the following public static final variables java.lang.Boolean.TYPE
, java.lang.Integer.TYPE
etc
这篇关于Integer.class 与 int.class的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!