首页 > 代码库 > Scala中的Apply

Scala中的Apply

/** * Created by Administrator on 2014-12-31. */class ApplyTest {  def apply() = "Apply customer"  def test(): Unit = {    println("test")  }}object ApplyTest{  def apply() = new ApplyTest  def static: Unit ={    println("i‘m a static method")  }}object Apply {  def main(args: Array[String]) {    val app = ApplyTest()  //这里使用的是object AppyTest  , 因为apply中实例化了class AppleTest,所以才能调用test    app.test    val app1 = new ApplyTest  //这里实例化的是class ApplyTest    app1.test    println(app())    println(app1())  }}

 

Scala中的Apply