Locked History Actions

Diff for "scala/import"

Differences between revisions 1 and 2
Deletions are marked like this. Additions are marked like this.
Line 9: Line 9:
  val bar = 123   val field = 123
Line 15: Line 15:
    println(bar)     println(field)
Line 23: Line 23:

== trait

import

オブジェクトのインポート

オブジェクトをインポートすることで、そのオブジェクトを指定しなくともメンバにアクセスできるよになる

class Foo {
  val field = 123
}
object Main {  
  def main(args: Array[String]) {
    val foo = new Foo
    import foo._
    println(field)
  }
}

結果は

123

== trait