package com.npnets.reflect;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class ReflectUtil {
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) throws Exception {
Class cla = Class.forName("com.npnets.reflect.Scheduler");//获取 Scheduler 类
Object obj = cla.newInstance();// 创建 Scheduler 对象
Field field = cla.getDeclaredField("itemId");// 获取 itemId 属性
System.out.println("--"+field.getType());
field.setAccessible(true);// 打开私有属性 itemId 的访问权限
field.set(obj, 19);// 为itemId 重新赋值
System.out.println(field.get(obj)); // 获取 obj 的 itemId 属性值
Method method = cla.getMethod("execute", String.class ,String.class);
String result = (String) method.invoke(obj ,"10", "20");
System.out.println(result);
System.out.println("".getClass());;
System.out.println(Class.forName("com.npnets.reflect.Scheduler"));
System.out.println(Integer.TYPE);
System.out.println(Scheduler.class);
System.out.println(int.class == Integer.TYPE);
}
}