当前位置:网站首页>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)
}
}
边栏推荐
- Registration method of native method in JNI
- 我想问一下兴业证券怎么开户?通过链接办理股票开户安全吗
- Go语言运算符(第8课下)
- Virtual machine - network configuration
- 2022安全员-C证考试模拟100题及在线模拟考试
- [redis realizes seckill service ②] solution to oversold problem
- Text editor of QT project practice ---------- episode 8
- Binder mechanism and Aidl communication example
- 腾讯云国际云服务器网络访问丢包问题解决办法
- Helm chart warehouse operation
猜你喜欢

QT (35) - operate excel qxlsx qaxobject

Meta & Berkeley proposed a universal multi-scale visual transformer based on pooled self attention mechanism. The classification accuracy in Imagenet reached 88.8%! Open source

Kubernetes 架构核心组件工作原理解析

Custom animation (simulated win10 loading animation)

Activity startup process

Use of file class filenamefilter & filefilter in io

2022R1快开门式压力容器操作考题及答案

Decoupling pages and components using lifecycle

ServerSocket and socket connection

51 single chip microcomputer multi computer communication
随机推荐
EVM Brief
热力图展示相关矩阵
Add information on the left and add parts on the right of the status bar
Infotnews | is the development of domestic NFT limited to digital collections?
Thingsboard - rest API obtains and refreshes tokens
断言(assert)的用法
百公里加速仅5.92秒,威兰达高性能版以高能产品实力领跑
Realization of MNIST handwritten numeral recognition
Text editor of QT project practice ---------- episode 11
Input series
生成订单30分钟未支付,则自动取消,该怎么实现?
Go crawler framework -colly actual combat (II) -- Douban top250 crawling
Go crawler framework -colly actual combat (I)
C# 闭包的垃圾回收
2021-04-18
[redis realizes seckill service ④] one order for one person, and cannot be purchased repeatedly
2022 melting welding and thermal cutting recurrent training question bank simulated examination platform operation
2022年危险化学品经营单位安全管理人员考试试题及模拟考试
2019 summary and 2020 outlook
ServerSocket and socket connection