//新建一个接口
@Retention(RetentionPolicy.RUNTIME)
public @interface DraweeViewAnnotation {
String name() default "Hello world";
}
//写一个实体类
public class Enetiy { @DraweeViewAnnotation(name = "Hello world") String name; public Enetiy(String name) { this.name = name; } @DraweeViewAnnotation(name = "Hello world") public String getName() { return name; } public void setName(String name) { this.name = name; } }
//获取name属性值
Class aClass = Class.forName("com.zjs.zhangjingshuai1203.Enetiy"); Method getName = aClass.getMethod("getName", null); DraweeViewAnnotation annotation = getName.getAnnotation(DraweeViewAnnotation.class); Toast.makeText(MainActivity.this, annotation.name()+"~", Toast.LENGTH_SHORT).show();