练习
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放到任意目录下,然后运行上面的编译,执行命令。
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放到任意目录下,然后运行上面的编译,执行命令。
相关文章推荐
- Spark RDD API详解(一) Map和Reduce
- 使用spark和spark mllib进行股票预测
- Windows下Scala环境搭建
- Spark随谈——开发指南(译)
- Spark,一种快速数据分析替代方案
- Windows7下安装Scala 2.9.2教程
- eclipse 开发 spark Streaming wordCount
- XML 文件解析--含Unicode字符的XML文件
- 分分钟掌握快速排序(Java / Scala 实现)
- Scala极速入门
- Spark初探
- Spark Streaming初探
- Scala实现REST操作
- Scala method call syntax
- 关于Scala多重继承的菱形问题
- Scala 高阶函数(high-order function)剖析
- Spray.io搭建Rest服务
- Spray.io搭建Rest — 支持Twirl模板并部署
- 搭建hadoop/spark集群环境