scala:注释访问器方法 [英] scala: annotating accessor methods
问题描述
class Foo {
@SomeAnnotation
var bar: String = _
}
@SomeAnnotation 是一个 Java 注释(因此它在运行时保留),具有运行时保留和方法目标.代码编译,但在运行时编译器生成的 bar() 和 bar_=() 方法没有被注释.
@SomeAnnotation is a Java annotation (so it is kept at runtime) with runtime retention and Method target. The code compiles, but at runtime the bar() and bar_=() methods that the compiler generated are not annotated.
假设这不是一个错误,是否有一种干净的方法来注释生成的 getter 方法而无需明确定义该方法?
Assuming this is not a bug, is there a clean way of annotating the generated getter method without needing to def the method explicitly?
推荐答案
这个邮件列表帖子可能有用:http://old.nabble.com/-scala--field-annotations,-getters-setters-and-BeanProperty-td24970781.html
This mailing list post might be of use: http://old.nabble.com/-scala--field-annotations,-getters-setters-and-BeanProperty-td24970781.html
这篇关于scala:注释访问器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!