我是Scala的新手,在Scala中我发现可以直接在类中写入println,尽管它不是变量或方法,这怎么可能?
即使println是一种方法,那么为什么我们不按照方法的要求在类中定义它呢?为什么尽管是一个方法,它不能直接在Java类中允许但在Scala中允许?
例如
class Hero {
println("running fine...") // Why is this println allowed in scala when its not inside a function?
}
object MainObject{
def main(args: Array[String]){
new Hero()
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
46 次 |
| 最近记录: |