反射我的簡潔記法

具體對象.getClass();
類名.class;
封裝類名.TYPE;
Class.forName("類名");

 Class  Field     Constructor  Method 

Class  
getFields() getConstructors() getMethods()

Field
 field.setAccessible(true);   field.set(obj, "男");  (field.get(對象)獲得field的引用)       
Constructor  
getModifiers()  getName() getParameterTypes() Modifier.toString(getModifiers())
newInstance("Rollen",20); (反射方式使用方法)

Method 
getModifiers()    getReturnType() getName() getParameterTypes() Modifier.toString(getModifiers())
method.invoke(demo.newInstance(),"Rollen",20);(反射方式使用方法)

Annotaion
(   getAnnotation(Class)  field.getAnnotations() );


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章