标签:object ted dem created ring 方法 creat ast 伴生对象
package cn.itcast
/**
* Created by lishas on 2016/8/22.
*/
object ApplyDemo {
def apply(): Unit ={
println("apply invoked")
}
def apply(name:String):String={
name
}
def apply(name:Int):Int={
println("Int")
name
}
def main(args: Array[String]) {
//val a=ApplyDemo("tom")
val a=ApplyDemo(10)
println(a)
val arr=Array(1,2,3,4,5,6,7,8,9)
}
}
当获取伴生对象,Array不加括号,加括号就是调用apply方法
标签:object ted dem created ring 方法 creat ast 伴生对象
原文地址:http://www.cnblogs.com/maomeng/p/6791520.html