当前位置:网站首页>Scala object
Scala object
2022-07-23 10:09:00 【u013250861】
1.1 What is? Scala Singleton objects in ?
Single case , Single case , seeing the name of a thing one thinks of its function , It has only one instance , There is no more . This is what distinguishes it from class Class place .
Scala Is an object-oriented programming language , Constant / Variable / Methods, etc. must be defined in class or object Just inside , It cannot be defined elsewhere . That is to say object object 、class A class is the only place where its members can be defined .
The key to define the object is object, It's an example , Not a blueprint , Therefore, it does not need external calls to execute its methods .
Like lazy variables , Singleton objects are created late , When it is first used, create .
Of course, you can create multiple singleton objects , You can also define objects in classes or methods , Naturally, you can also reference methods or constants in another object in one object or class . If you want to reference the method of an object in another script in one script , You need to import The path of the incoming object .
Be careful : A singleton object is globally unique , So it has a stable path . That is, you cannot create two objects with the same name , No longer the same path , Not anywhere .
1.2 Why choose singleton ?
Every program needs a point from execution . stay OOPS in , Classes need objects to execute . But it needs to be implemented first main() Method to call other members of the class .
In order to be in scala In the implementation of main() Method , Many object-oriented programming languages use static keyword , however scala Not in the programming language static keyword .
Is that why Scala In, we use the definition main Method .
1.3 Characteristics of singleton objects (Features of singleton object)
Use object Keyword creation .
The members in the object are global members , That is, members can be called from anywhere in the program .
A singleton object cannot create an instance . That is, it can only have a unique instance is itself .
Allow to inherit , That is, inheritance can extend classes and features . (it can extend class and traits.)
If you want to reference in a singleton object Members in another singleton object , We will use The name of the reference singleton object . { The name of the reference singleton object }. The name of the reference singleton object .{ Member name } The method of quoting .
Reference material :
9、Scala object object
边栏推荐
- 【C语言基础】14 文件、声明和格式化输入输出
- Want to give up software testing, 4 years of experience to interview 10 minutes, the test is now so difficult?
- [learning notes] node -- from 0 foundation to actual enterprise official website
- 可视化全链路日志追踪
- Scala对象object
- 数据库安全性和数据的完整性
- 华泰证劵开户有骗局吗安全吗
- 系统安全测试要怎么做,详细来说说
- 幻核即将关闭?数字藏品还有未来吗?
- BGP反射器,联邦,选路规则
猜你喜欢

中小企业的福音来咯!JNPF渐火,助力业务数字化升级

How can a platform enterprise solve the business of ledger accounting?

The technical points of the new project can be guided if necessary

This tool complements the last kilometer of JMeter performance analysis

30行自己写并发工具类(Semaphore, CyclicBarrier, CountDownLatch)是什么体验?

笔记——记录一个dynamic-datasource please check the setting of primary 问题解决

spark分区算子partitionBy、coalesce、repartition

网络通信原理与IP地址的分配原理,网络七层由下往上分别为物理层、数据链路层、网络层、传输层、会话层、表示层和应用层

这个工具,补齐了 JMeter性能分析最后一公里短板

Transfer software testing salary 10K | there is food in the hand and a bottom in the heart, which is the truth at all times
随机推荐
如何将list中相同字段值归类在同一个list下
亿级融资事件占比超30%,超自动化的下一站是何处?丨曼孚科技
拓扑排序 & 关键路径
C语言柔性数组
【学习笔记】Node--从0基础到实战企业官网
Android开发学习日记--内容提供者(跨应用间的数据库修改)
指针的底层机制
幻核即将关闭?数字藏品还有未来吗?
Is CITIC futures a regular futures company and is it safe to open an account?
The method of page Jump in PHP
d类型不同的模板错误
JS div scroll to the bottom
平台型企业如何解决分账核算业务呢?
The technical points of the new project can be guided if necessary
567. Arrangement of strings
Seven sorts -- detailed explanation of ten thousand words
新的项目实现的技术点如有需要可以指导
Is the sub database and sub table really suitable for your system? Talk about how to select sub databases, sub tables and newsql
适合短视频分享的Fireshare
华泰证券开户安全性高吗,怎么办理