3

Can anyone show me how to add annotation to a field using JavaPoet?

All examples I've managed to explore so far are about adding annotations to the classes and methods.

It looks like I'm missing something pretty straighforward here.

shabunc
  • 17,863
  • 15
  • 68
  • 96

1 Answers1

5

Hooray, I've figured it out, so might be it would be a help for someone else:

typeSpecBuilder
          .addField(
              FieldSpec.builder(<SomeClass>, <name>)
                  .addAnnotation(<AnnotationClass>)
                  .addModifiers(Modifier.PUBLIC)
                  .build()
          );
shabunc
  • 17,863
  • 15
  • 68
  • 96