Integer.class 与 int.class [英] Integer.class vs int.class

查看:22
本文介绍了Integer.class 与 int.class的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Integer.classInteger.TYPEint.class 有什么区别?

What is the difference between Integer.class, Integer.TYPE and int.class?

告诉我

  1. Integer.class 是 Integer (Wrapper) Class 对象的引用
  2. 但是什么是 int.class 作为 int 不是一个类,它是一个原始类型.Integer.TYPE 指的是什么?
  1. Integer.class is a reference of Integer (Wrapper) Class object
  2. but what is then int.class as int is not a class, it's a primitive type. And what does Integer.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.TYPEjava.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屋!

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