Scala Apply
2024-09-16 05:59:32
class ApplyTest{
//一定要写(),不加括号就报错。
def apply() = println("Into Spark!")
def havaAtry(){
println("have a try!")
}
}
object ApplyTest{
//一定要写(),不加括号就报错。
def apply() = new ApplyTest
}
//调用时:
val test = ApplyTest()
test.haveAtry()
//类名+(),相当于调用class的Apply()方法。
println(test())
//类名后面加括号,相当于调用伴生对象的apply方法
最新文章
- Rethink your own
- 《BI项目笔记》创建时间维度(1)
- Lua.LearningLua.7-userdata
- 更改printk打印级别
- Linux进程控制(一)
- IIS Express start introduction and applicationHost modification
- poj 1915 http://poj.org/problem?id=1915
- SQL Server 对象
- Catalog和Schema
- 你想建设一个能承受500万PV/每天的网站吗?如果计算呢?(转)
- Spring MVC返回的json如何去除根节点名称
- javascript的关键所在---作用域链
- python 函数递归
- 统计numpy数组中最频繁出现的值
- 15树莓派安装图形界面截图工具Shutter
- 上下文调用(call , apply , bind)
- vue.js computed,watch的区别
- Python hasattr,getattr,setattr,delattr
- 一个第三方Dart库导致的编译错误!
- Windows下RabbitMQ安装及配置