Locked History Actions

Diff for "scala/selfTypeAnnotation"

Differences between revisions 1 and 2
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

自分型アノテーションの用途は二つある。

 * 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
}}}

自分型アノテーション

自分型アノテーションの用途は二つある。

  • 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