views:

126

answers:

2
class Foo {
  @SomeAnnotation
  var bar: String = _
}

@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.

Assuming this is not a bug, is there a clean way of annotating the generated getter method without needing to def the method explicitly?

+2  A: 

This mailing list post might be of use: http://old.nabble.com/-scala--field-annotations,-getters-setters-and-BeanProperty-td24970781.html

King Cub
+2  A: 

Yes, you need to use the meta-annotations in scala.annotation.target. See the documentation in https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/src/library/scala/annotation/target/getter.scala

Lukas Rytz
Note that this is a new feature of Scala 2.8. I think from your description you may be using this already, as in 2.7 *both* the field and the accessor methods were annotated.
retronym