There are three ways to get a class
entity classes and Interfaces
Public interface Person {
public void Sayhi ();
}
public class Student implements person{
Private String ID;
private String name;
private int age;
public int sex=1;
/*get and Set methods omitted */
}
Class C1 = Student.class;
Class c2=class.forname ("com.study.reflect.Student"); You must bring the package name here.
Class c3=new Student (). GetClass ();
System.out.println (C1==C2);
System.out.println (C1==C3);
Output: True True
Why are all true:
First of all, you have to understand that in Java any class to be loaded on the virtual machine to run, the above three ways is the JVM to find and load the specified class, since all are the same class, then the return of the results are definitely the same!
This article is from the "Programmer rookie" blog, be sure to keep this source http://5345468.blog.51cto.com/5335468/1688642
Reflection acquisition class, property, method, interface, parent class, etc.