'How to create my own annotation, nothing works
I'm trying to make my own getter annotation, as it is done in lombok:
package testAnns.anns;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Get {
Access value() default Access.PUBLIC;
Value[] method() default {};
@Retention(RetentionPolicy.RUNTIME)
@Target({})
@interface Value {}
}
Tried to specify:
package testAnns;
import testAnns.anns.Get;
public class TestAnns {
@Get public int l = 10;
}
I try to call:
public static void main(String[] args) {
TestAnns ann = new TestAnns();
System.out.println(ann.getL()); // error
}
Nothing works.
What to do, how to be, why does not work?
Connoisseurs, please help me figure it out, I don’t understand why it doesn’t work ...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
