Of course it is. Here is a sample annotation:
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface TestAnnotation {
String testText();
}
And a sample annotated method:
class TestClass {
@TestAnnotation(testText="zyx")
public void doSomething() {}
}
And a sample method in another class that prints the value of the testText:
Method[] methods = TestClass.class.getMethods();
for (Method m : methods) {
if (m.isAnnotationPresent(TestAnnotation.class)) {
TestAnnotation ta = m.getAnnotation(TestAnnotation.class);
System.out.println(ta.testText());
}
}
Not much different for field annotations like yours.
Cheerz!