1

Hi I am currently trying my hand at an AnnotationProcessor for Java. The only problem I have now is how to get the Declared Fields for the class over which the annotation is placed.

Does anyone know how to get the fields?

1 Answer 1

3

Once you get the element, you loop over the enclosed elements and filter by element kind:

typeElement.getEnclosedElements().stream()
                .filter(e -> ElementKind.FIELD.equals(e.getKind()))
                .collect(Collectors.toList());
Sign up to request clarification or add additional context in comments.

1 Comment

Also able to use == instead of equals because kind is enum

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.