关于Java反射中基本类型的class问题
1. 基本类型的class和其对应包装类的class是不同的,所以在获得Method指定参数的时候,需要精确指定参数的类型,即 setInt(int x) 无法使用 getMethod("setInt",Integer.class) 获得。
2. 基本类型的class无法通过Class.forName方法获得,可以通过 类型名.class 或者 对应包装类的静态字段 TYPE 获得。
若要动态获得基本类型的class,可以考虑把class存进一个Map中进行读取。
Class<Integer> clazz = int.class;