title: how to get the annotation of a scala class field
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5177010/how-to-create-annotations-and-get-them-in-scala">How to create annotations and get them in scala</a>  </p>
  </blockquote>
  
  
  
  <p>other examples get the annotation of a annotated class. What I would like to do is to get the annotation of a class field (version in this test), something like this: </p>
  
  <pre><code>import java.lang.annotation.{RetentionPolicy, Retention}
  import annotation.meta.field
  
  class AttribField() extends scala.annotation.StaticAnnotation
  object MyTypes { type Attrib = AttribField @field }
  import MyTypes._
  case class TestClass(@Retention(RetentionPolicy.RUNTIME) 
                       @Attrib version: Option[String])
  object TestMe {
    def main(args: Array[String]) {
      val testObj = new TestClass(version = Some("1"))
      testObj.getClass.getDeclaredFields.foreach(field =&gt; {
    field.setAccessible(true)
    println("field: name=" + field.getName + " value=" + field.get(testObj))
    field.getAnnotations.foreach(x =&gt; println("x="+x))  // nothing in here
    field.getDeclaredAnnotations.foreach(x =&gt; println("y="+x))  // nothing in here
    // does not even compile
  //     field.getAnnotation(classOf[AttribField])
     })
    }
  }
  </code></pre>
  
  <p>I want to test if there is a certain annotation, then branch.
  But I cannot pass go. There must be something fundamental that I missed, but what?</p>