自分型アノテーション
自分型アノテーションの用途は二つある。
- thisの別名を定義する。
thisの別名を定義する
object SelfTypeAnnotationSample1 { self => // 自分型アノテーション。=>の右側には何もない。「class Internal」を指しているわけでもない。 class Internal { def procedure = { SelfTypeAnnotationSample1.this.procedure self.procedure } } def procedure = { println("hello world") } def main(args: Array[String]) { new Internal().procedure } }
この結果は
hello world hello world