Vinicius Seufitele
Vinicius Seufitele

Reputation: 895

How to create custom annotations like BeanProperty

In Scala it's possible to use the annotation @BeanProperty to automatically generate getters and setters to a field.

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

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

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

Thanks.

Upvotes: 7

Views: 791

Answers (1)

leedm777
leedm777

Reputation: 24032

Two words: compiler plugin. It is not easy, and the documentation is sparse, but that is one way to do it.

Future versions of Scala will likely have macro support, which gives you much of the same flexability.

Upvotes: 9

Related Questions