Package Com.huawei.pia;
Import Java.lang.reflect.Constructor;
Import Java.lang.reflect.Field;
Import Java.lang.reflect.Modifier;
public class person extends SuperClass1 implements Inter1,inter2 {
private String name;
private int age;
Public person (String Name,int age) {
THIS.name = name;
This.age = age;
}
Public person () {};
Public String GetName () {
return name;
}
public void SetName (String name) {
THIS.name = name;
}
public int getage () {
return age;
}
public void Setage (int.) {
This.age = age;
}
@Override
Public String toString () {
TODO auto-generated method stubs
Return "[" + THIS.name + ":" + This.age + "]";
}
Static Class hello{
public static void Main (string[] args) {
Class<?> demo = null;
try {
Demo = Class.forName ("Com.huawei.pia.Person");
} catch (ClassNotFoundException e) {
E.printstacktrace ();
}
field[] field = Demo.getdeclaredfields ();
for (int i = 0; i < field.length; i++) {
Get modifier
int mo = Field[i].getmodifiers ();
String priv = modifier.tostring (MO);
Property type
class<?> type = Field[i].gettype ();
System.out.println ("modifier:" +priv+ ", \ n attribute type:" +type+ ", \ n Property Name:" +field[i].getname () ");
}
Get the construction method
Constructor<?>[] cons = Demo.getconstructors ();
for (int i = 0; i < cons.length; i++) {
System.out.println ("Construction Method:" +cons[i].getname ());
}
Get interface
class<?> inter[] = demo.getinterfaces ();
for (int i = 0; i < inter.length; i++) {
SYSTEM.OUT.PRINTLN ("interface" + (i+1) + ":" +inter[i].getname ());
}
Get the parent class
Class<?> superclass = Demo.getsuperclass ();
System.out.println ("Parent class:" +superclass.getname ());
}
}
}
Java Reflection correlation-Gets the entire schema of a class through class