How to create custom annotations like BeanProperty

In Scala, you can use the @BeanProperty annotation to automatically generate getters and setters in a field.

How can I create my own annotation that behaves like this?

I'm interested in creating annotations that change the source code, like @BeanProperty.

As an example, how can I create an annotation that only generated get methods?

Thanks.

+7
source share
1 answer

Two words: compiler plugin . This is not easy, and the documentation is sparse, but this is one way to do this.

Future versions of Scala will most likely have macro support , giving you more flexibility.

+9
source

All Articles