Home >Java >javaTutorial >Methods of predefined Class objects in java
Basic Java types (boolean, byte, char, short, int, long, float and double) and the keyword void are also represented as Class objects through the class attribute;
Class boolean isPrimitive() in class: Determines whether the specified Class object represents a basic type.
Static TYPE fields of packaging classes and Void classes;
Integer.TYPE == int.class ; Integer.class == int.class;
Class instance objects of array types:
Class clz = String[].class;
How to compare the Class objects of arrays to see if they are equal? Dimensions of arrays and the type of the array;
isArray() method in the Class class: Determines whether this Class object represents an array type..
package junereflect624; public class PreClassDemo2 { public static void main(String[] args) { Class> in = int.class; System.out.println(in);//int Class> in2 = Integer.class; //包装类都有一个常量TYPE,用来表示其基本数据类型的字节码 Class> in3 = Integer.TYPE; System.out.println(in2);//class java.lang.Integer System.out.println(in3);//int System.out.println(in3 == in);//true 包装类都有一个常量TYPE,用来表示其基本数据类型的字节码,所以这里会相等! System.out.println(in3 == in2);//false Class s = String [].class; Class i = int [].class; //System.out.println(i ==s);//编译根本就通过不了,一个是int,一个是String } //这两个自定义的方法是可以的,一个int,一个Integer//包装类与基本数据类型的字节码是不一样的 public void show(int i){} public void show(Integer i){} }
The above is the detailed content of Methods of predefined Class objects in java. For more information, please follow other related articles on the PHP Chinese website!