What is it possible to use your own annotation in java? What practical application is possible for a class that is annoyed by the annotation created?
@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Question { String data(); int data2(); } @Question(data = "What Next?", data2 = 1) public class MyObj { private String name; private Integer id; public MyObj(String name, Integer id) { this.name = name; this.id = id; } public String getName() { return name; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof MyObj)) return false; MyObj myObj = (MyObj) o; return id.equals(myObj.id); } @Override public int hashCode() { return id.hashCode(); } }
It turns out that through reflection it is possible to obtain the values recorded in the annotation for a particular class.
And what practical application of this information is possible?