scala手动编译运行

 

1  Person.scala

class Person {
var name = ""
var age = 0
}

object Person {
    // a one-arg constructor
    def apply(name: String): Person = {
    var p = new Person
    p.name = name
    p
    }

    def apply(name: String, age: Int): Person = {
    var p = new Person
    p.name = name
    p.age = age
    p
    }
}

2 Test.scala

object Test extends App {  
    
   override def main(args: Array[String]) = {  
      val p = Person("xxx") 
          
         println(s" hello, ${p.name}"  )
    }  
} 

3 键入命令 进行编译和运行 最后得到输出结果

  3.1 编译 ysuse@linux-oxnr:~/Desktop> scalac Test.scala Person.scala 

  3.2 运行 ysuse@linux-oxnr:~/Desktop> scala Test

  3.3 输出 hello, xxx

这个是把scala加入到运行环境当中,便于以后在任何地方直接用scala工具

     export PATH=/opt/scala-2.11.7/bin:$PATH

 

posted on 2016-01-04 15:52  rojas  阅读(433)  评论(0编辑  收藏  举报