您的位置:首页 > 其它

练习

2015-10-21 20:56 295 查看

SparkILoop.scala

package  tony.scala.sample
//importtony.scala.sample._
class  Aaa {
   override  def   toString = "I am Aaa"
}

class  SparkILoop extends Aaa with SparkILoopInit {
   override  def   toString = "I am SparkILoop"
   private[sample]  def   echo(msg: String) = {
     println(msg)
   }
}

private[sample]  trait SparkILoopInit {
   self:SparkILoop => //注释掉,看看什么效果!!!
   override  def   toString = {
     "I am SparkILoopInit"
   }
//test "Explicitly Typed Self References"
def  typeSelfReference = echo("echo works here!")
}

object  Test {
def  main(args: Array[String]) {
val  a : Aaa = new SparkILoop
val  b : SparkILoopInit = new SparkILoop
println(a)
println(b)
b.typeSelfReference
}
}
编译:
scalac SparkILoop.scala
运行:
scala tony.scala.sample.Test
注:在scala中,文件放置不用像Java一样必须按照package的目录结构。对于本例,可以把SparkILoop.scala放到任意目录下,然后运行上面的编译,执行命令。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  scala spark