如何创建像定制的BeanProperty注解 [英] How to create custom annotations like BeanProperty

查看:122
本文介绍了如何创建像定制的BeanProperty注解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Scala中有可能使用注释@BeanProperty自动生成getter和setter一个字段。

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?

我感兴趣的创建改变了源$ C ​​$ C,像@BeanProperty做注解。

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

作为一个例子,我怎么可能创建仅产生get方法注释?

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

感谢。

推荐答案

两个词:编译器插件。这是不容易的,和文档是稀疏,但就是这样做的一种方式。

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

斯卡拉的未来版本将可能有宏支持,它给你几乎相同的flexability的。

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

这篇关于如何创建像定制的BeanProperty注解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆