Java 什么';这是int.class的目的和功能

Java 什么';这是int.class的目的和功能,java,Java,我无意中发现这是可行的: Class<?> a; a = int.class; System.out.println(a); // int a = Integer.class; System.out.println(a); // class java.lang.Integer a类; a=整数类; 系统输出打印ln(a);//int a=整数.class; 系统输出打印ln(a);//类java.lang.Integer 它对原语到底意味着什么 我试过了,List

我无意中发现这是可行的:

Class<?> a;

a = int.class;
System.out.println(a); // int

a = Integer.class;      
System.out.println(a); // class java.lang.Integer
a类;
a=整数类;
系统输出打印ln(a);//int
a=整数.class;
系统输出打印ln(a);//类java.lang.Integer
它对原语到底意味着什么

我试过了,
List
List
都不起作用(是的,我知道我必须使用整数)。而且,很明显,我不能在原语上调用
getClass()
,因此它对于任何类型的类型检查都是无用的


在什么情况下我会使用
int.class
,为什么它会出现在语言中?

当您试图通过反射API查找具有int参数的方法时,您会使用它。

来自规范:

The type of p.class, where p is the name of a primitive type 
(§4.2), is Class<B>, where B is the type of an expression of 
type p after boxing conversion (§5.1.7).
那你呢

Class<Integer> a = int.class;
Class a=int.Class;

何时使用:许多反射用例(例如在argparse4j中,他们使用它从命令行参数映射到方法)。

哦,天哪,
void.class
!在规范中。
Class<Integer> a = int.class;