如何创建自定义注释,如 BeanProperty [英] How to create custom annotations like BeanProperty

查看:31
本文介绍了如何创建自定义注释,如 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?

我对创建更改源代码的注释很感兴趣,就像 @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.

Scala 的未来版本可能会提供宏支持,这为您提供了相同的灵活性.

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

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

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