WorkerValue wv = new WorkerValue("홍길동", WorkerValue.POSITION_MANAGER);
Class<?> clazz1 = WorkerValue.class;
Class clazz2 = wv.getClass();
Class clazz3 = null;
try {
clazz3=Class.forName("reflex.WorkerValue");
}catch(Exception e) {
e.printStackTrace();
}
System.out.println(System.identityHashCode(clazz1));
System.out.println(System.identityHashCode(clazz2));
System.out.println(System.identityHashCode(clazz3));
System.out.println(System.identityHashCode(null));
Class clazz = WorkerValue.class;
Constructor[] constructors = clazz.getConstructors();
System.out.println("====constructors=====");
for(int i = 0; i < constructors.length;i++) {
System.out.println(constructors[i].toString());
}
Method[] Methods = clazz.getDeclaredMethods();
System.out.println("====Method=====");
for(int i = 0; i < Methods.length;i++) {
System.out.println(Methods[i].toString());
}
Field[] fields = clazz.getFields();
System.out.println("====fields=====") ;
for(int i = 0; i < fields.length;i++) {
System.out.println(fields[i].toString());
}
WorkerValue wv = new WorkerValue("홍길동", WorkerValue.POSITION_MANAGER);
Class clazz = wv.getClass();
try {
Object obj = clazz.getConstructor().newInstance();
if(obj instanceof WorkerValue) {
System.out.println("이건 워커벨류 클레스 오브젝트임");
WorkerValue wv2 = (WorkerValue)obj;
wv2.setName("임꺽정");
wv2.setPosition(WorkerValue.POSITION_EMPLOYEE);
System.out.println(wv2.toString());
}
}catch(Exception e) {
e.printStackTrace();
}
Class<?> aCls = B.class;
Constructor<?> constroctor = aCls.getConstructor();
B b = (B)constroctor.newInstance();
System.out.println(b.f());