How to create custom annotations like BeanProperty

风流意气都作罢 提交于 2020-01-03 08:52:37

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/10057119/how-to-create-custom-annotations-like-beanproperty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!