1. Class: 是一個類; 一個描述類的類.
封裝了描述方法的 Method,
描述字段的 Filed,
描述構造器的 Constructor 等屬性.
2. 如何得到 Class 對象:
2.1 Person.class
2.2 person.getClass()
2.3 Class.forName("com.atguigu.javase.Person")
3. 關於 Method:
3.1 如何獲取 Method:
1). getDeclaredMethods: 得到 Method 的數組.
2). getDeclaredMethod(String methondName, Class ... parameterTypes)
3.2 如何調用 Method
1). 如果方法時 private 修飾的, 需要先調用 Method 的 setAccessible(true), 使其變爲可訪問
2). method.invoke(obj, Object ... args);
4. 關於 Field:
4.1 如何獲取 Field: getField(String fieldName)
4.2 如何獲取 Field 的值:
1). setAccessible(true)
2). field.get(Object obj)
4.3 如何設置 Field 的值:
field.set(Obejct obj, Object val)
5. 瞭解 Constructor 和 Annotation
6. 反射和泛型.
6.1 getGenericSuperClass: 獲取帶泛型參數的父類, 返回值爲: BaseDao<Employee, String>
6.2 Type 的子接口: ParameterizedType
6.3 可以調用 ParameterizedType 的 Type[] getActualTypeArguments() 獲取泛型參數的數組.