码迷,mamicode.com
首页 > 移动开发 > 详细

Scala中的Apply

时间:2014-12-31 07:37:11      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

/**
 * 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

标签:

原文地址:http://www.cnblogs.com/hark0623/p/4194940.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!