当前位置:网站首页>Default methods for Scala sample classes
Default methods for Scala sample classes
2022-06-25 01:03:00 【Jue Niu thunder plough hot blade】
// Demonstrates the default methods of the sample class
object The default method of the sample class {
case class Person(var name: String, var age: Int) {
}
def main(args: Array[String]): Unit = {
// apply(): Create objects quickly , Omit new keyword
val p1 = Person(" Zhang San ", 18)
// toString(): Output statement , Call this method by default
println(p1)
// equals(): Let's go through == Compare whether the attribute values of two objects are the same in the form of
val p2 = Person(" Zhang San ", 18)
println(p1 == p2)
// hashCode(): Get the hash value of the object
// The hash value of the same object must be the same , The hash values of different objects are generally different
println(p1.hashCode())
println(p2.hashCode())
println("-" * 20)
// special case : The content is different , The hash value is the same
println(" important ".hashCode)
println(" conversation ".hashCode)
// copy(): Let's build on existing objects , Quickly build a similar object
val p3 = p2.copy(age = 20)
println(p3)
}
}
边栏推荐
- 【微服务|Sentinel】实时监控|RT|吞吐量|并发数|QPS
- [redis realizes seckill service ②] solution to oversold problem
- Go crawler framework -colly actual combat (4) -- Zhihu answer crawl (2) -- visual word cloud
- Sanic service startup failed
- Text editor for QT project practice - Episode 10
- 在企业级开发过程中我发现有位同事用select * from where 条件 for update
- Simulation questions and answers of the latest national fire facility operator (senior fire facility operator) in 2022
- Unimportant tokens can be stopped in advance! NVIDIA proposes an efficient visual transformer network a-vit with adaptive token to improve the throughput of the model
- 51 single chip microcomputer multi computer communication
- Text border format and text block of rich text
猜你喜欢
The basic principle and application of iterator and enhanced for
Preliminary understanding of qtoolbutton
Examination questions and mock examination for safety management personnel of hazardous chemical business units in 2022
Applet opening traffic master
Easy to wear - drop down radio
Encryption and encoding resolution
Single blind box removal, social blind box and friend blind box program source code
2021-11-07
Use of navigation and navigationui
热力图展示相关矩阵
随机推荐
ros(24):error: invalid initialization of reference of type ‘xx’ from expression of type ‘xx’
108 pages (40000 words) proposal for future apartment intelligent design platform project (version 2022)
Realization of MNIST handwritten numeral recognition
51单片机多机通信
Some examples of MgO operating database in go
If the order has not been paid for 30 minutes, it will be automatically cancelled. How can I achieve this?
2022r1 quick opening pressure vessel operation test questions and answers
placeholder
百公里加速仅5.92秒,威兰达高性能版以高能产品实力领跑
Text editor for QT project practice -- Episode 9
In the process of enterprise development, I found that a colleague used the select * from where condition for update
Simulation questions and answers of the latest national fire facility operator (senior fire facility operator) in 2022
2021-04-18
C#和C 的CAN通信实验
A plug-in framework for implementing registration free and login verification with hook technology
2022 crane driver (limited to bridge crane) examination question bank simulated examination platform operation
Use of navigation and navigationui
实现mnist手写数字识别
JSON file of China's provincial boundaries
Go crawler framework -colly actual combat (III) -- panoramic cartoon picture capture and download