首页 > 移动平台 > 详细

Scala中的Apply

时间:2014-12-31 07:35:08      阅读:260      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!