```
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
public class Reflect {
@
Target(ElementType.FIELD)
@
Retention(RetentionPolicy.RUNTIME)
@
Documented public @
interface FruitName {
String value() default "";
}
public static class Apple {
@
FruitName("apple")
public String name;
}
public static void main(String... args) throws Exception {
Apple apple = new Apple();
Class clz = apple.getClass();
Field[] fields = clz.getDeclaredFields();
for (Field field : fields) {
if (field.isAnnotationPresent(FruitName.class)) {
field.set(apple, field.getAnnotation(FruitName.class).value());
}
}
System.out.println(
apple.name);
}
}
```
http://tutorials.jenkov.com/java-reflection/annotations.htmlhttps://keyholesoftware.com/2014/09/15/java-annotations-using-reflection/http://www.journaldev.com/1789/java-reflection-example-tutorialhttps://docs.oracle.com/javase/tutorial/reflect/member/fieldValues.html