前言

java中的反射的底层实现是,在jvm的Classloader获得全限定名来创建Class。

正文

获得反射类型对象

1.类名.class

不执行静态快

2..Class<?> getClass()
Returns the runtime class of this Object.

3.static Class<?> forName(String className)
Returns the Class object associated with the class or interface with the given string name.会执行静态快

通过Class对象获得当前类的构造器、属性和方法

1.Constructor<?>[] getDeclaredConstructors()
Returns an array of Constructor objects reflecting all the constructors declared by the class represented by this Class object.获得当前类声明的所有构造器

2.Constructor<?>[] getConstructors()
Returns an array containing Constructor objects reflecting all the public constructors of the class represented by this Class object.获得当前类公共的构造器

3.Field[] getDeclaredFields()
Returns an array of Fie