当前位置:网站首页>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)
}
}
边栏推荐
- Thingsboard - rest API obtains and refreshes tokens
- Previous basic review (link)
- 图书馆管理系统代码源码(php+css+js+mysql) 完整的代码源码
- adb shell getevent
- ros(25):rqt_image_view报错Unable to load plugin for transport ‘compressed‘, error string
- Usage of ViewModel and livedata in jetpack
- Xcode preview displays a bug in the content of the list view and its solution
- 腾讯云国际云服务器网络访问丢包问题解决办法
- Go crawler framework -colly actual combat (III) -- panoramic cartoon picture capture and download
- 108页(4万字)未来公寓智能化设计平台项目方案建议书2022版
猜你喜欢

传输层 以字节为单位的滑动窗口技术

Preliminary understanding of qtoolbutton

热力图展示相关矩阵

Punch smart spirit 1. The brand is attractive. What is the strength of the product?

Infotnews | is the development of domestic NFT limited to digital collections?

2022年起重机司机(限桥式起重机)考试题库模拟考试平台操作

Wallpaper applet wechat applet

Go crawler framework -colly actual combat (III) -- panoramic cartoon picture capture and download
![[redis realizes seckill business ③] specific implementation of optimistic lock for oversold problem](/img/01/5ec4e5dae1748dce3d5dee33a24b0b.png)
[redis realizes seckill business ③] specific implementation of optimistic lock for oversold problem

Use of navigation and navigationui
随机推荐
【微服务|Sentinel】簇点链路|微服务集群环境搭建
2022R1快开门式压力容器操作考题及答案
Go crawler framework -colly actual combat (I)
Sanic service startup failed
Hot fix sophix multi-channel patch solution
51单片机多机通信
JMeter socket connection sends data
Use of file class filenamefilter & filefilter in io
adb shell sendevent
Go语言运算符(第8课下)
VNC viewer remote connection raspberry pie without display
Helm chart warehouse operation
Use and click of multitypeadapter in recycleview
Sliding window technology based on byte in transport layer
Usage of ViewModel and livedata in jetpack
Go crawler framework -colly actual combat (II) -- Douban top250 crawling
Activity startup process
2022熔化焊接与热切割复训题库模拟考试平台操作
QT(35)-操作EXCEL-QXlsx-QAxObject
Custom control - round dot progress bar (imitating one key acceleration in security guard)