且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java反射调用具有原始类型的构造函数

更新时间:2022-03-19 00:15:17

使用 Integer.TYPE 而不是 Integer.class.

根据 Javadocs,这是代表原始类型int的Class实例."

As per the Javadocs, this is "The Class instance representing the primitive type int."

您也可以使用 int.class.它是 Integer.TYPE 的快捷方式.不仅是类,甚至对于原始类型,您也可以在 Java 中使用 type.class.

You can also use int.class. It's a shortcut for Integer.TYPE. Not only classes, even for primitive types you can say type.class in Java.