scala/annotations

アノテーション

参考

Javaに劣るScalaの機能

サンプル

package testing;
import java.lang.annotation.*;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface SomeAnno {
  String something();
}

@SomeAnno(something="/foo/bar")
class AnnoTest {  
}

class NoTest {
}

object Annotations {

  def main(args: Array[String]) {    
    val someAnno = classOf[AnnoTest].getAnnotation(classOf[SomeAnno])
    println(someAnno.something)    
    val noAnno = classOf[NoTest].getAnnotation(classOf[SomeAnno])
    println(noAnno)
  }
}

実行結果

/foo/bar
null
last edited 2011-10-25 01:17:05 by ysugimura