当前位置:网站首页>The class declared by the scala object keyword directly calls methods and associated objects
The class declared by the scala object keyword directly calls methods and associated objects
2022-07-27 16:33:00 【But don't ask about the future】
object Student {
def test(): Unit = {
println("test")
}
}
object T5 {
def main(args: Array[String]): Unit = {
Student.test()
}
}
Static syntax is not object-oriented , therefore scala There is no static syntax in , In order to and java compatible , therefore scala Provide singleton objects to simulate static operations . Use Object Keyword declared class , Such as Student , can Directly access methods through class names , Such as Student.test().Student , Will produce 2 A class file , One is The current class Class files , The other is The current class $ Class files 
Class name $ Class in class file of The constructor is privatized , Cannot build objects directly , Inside the class Static code block You can return objects , And this object has only one , be called Singleton object , You can access the methods through this object 
Student.test() The singleton object is actually used Student$.MODULE$, namely Companion : Object The declared class is accompanied by the singleton object generated by the class
边栏推荐
- C language output string in reverse order
- 第21回---第30回
- The solution to the memory exhaustion problem when PHP circulates a large amount of data
- const小结
- MapReduce instance (II): Average
- matlab legend用法
- The whereor method of TP5 has many conditions
- 将IAR工程文件夹转移目录后无法进入函数定义解决
- Your password does not satisfy the current policy requirements (modify MySQL password policy setting simple password)
- 指针总结
猜你喜欢

Opencv (IV) -- image features and target detection

OpenCV(四)——图像特征与目标检测

【论文阅读】Transformer with Transfer CNN for Remote-Sensing-ImageObject Detection

Flume incrementally collects MySQL data to Kafka

training on multiple GPUs pytorch

ADAMS中转动整个模型

Axure install Icon Font Catalog

C channel simply implements the publishing and subscription of message queue

MapReduce instance (II): Average

Implementation of filler creator material editing tool
随机推荐
Install MySQL using CentOS yum
OpenCV(一)——图像基础知识
IO流简介
Time series - use tsfresh for classification tasks
Is low code the future of development? On low code platform
DRF learning notes (III): model class serializer modelserializer
Snowflake ID (go Implementation)
第31回---第52回
Cron expression use
DEX and AMMS of DFI security
Thesis reduction
HowNet and Wanfang database download papers for free ----- several times faster than connecting to the school intranet (some schools Wanfang database does not support downloading)
Your password does not satisfy the current policy requirements (modify MySQL password policy setting simple password)
TP5 paging some small points
Crmeb Pro v1.4 makes the user experience more brilliant!
Simulation生成报表
Firefox old version
SolidWorks Simulation曲线图属性设定
Chapter I Marxist philosophy is a scientific world outlook and methodology
Introduction to JWT