当前位置:网站首页>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)
}
}
边栏推荐
- Can communication experiment between C and C
- Working principle analysis of kubernetes architecture core components
- Use and click of multitypeadapter in recycleview
- Uniapp encapsulated incentive advertisement, screen insert advertisement and banner advertisement
- Golang示例续期锁:Redis+Channel+sync.Mutex
- Mobile security tool -dex2jar
- 打卡smart精灵#1,品牌不缺吸引力,产品本身实力如何?
- 我想问一下兴业证券怎么开户?通过链接办理股票开户安全吗
- 2022r1 quick opening pressure vessel operation test questions and answers
- Jar package merging using Apache ant
猜你喜欢

Use and click of multitypeadapter in recycleview

Go crawler framework -colly actual combat (II) -- Douban top250 crawling

Text editor for QT project practice - Episode 12

ros(24):error: invalid initialization of reference of type ‘xx’ from expression of type ‘xx’

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

Decoupling pages and components using lifecycle

51单片机多机通信

生成订单30分钟未支付,则自动取消,该怎么实现?

Network request -volley
![[redis realizes seckill service ②] solution to oversold problem](/img/b6/3073def06a56565894c28e49767e3e.png)
[redis realizes seckill service ②] solution to oversold problem
随机推荐
[microservices sentinel] cluster link | microservices cluster environment construction
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
redis + lua实现分布式接口限流实现方案
Garbage collection of C closure
C# 闭包的垃圾回收
Examination questions and mock examination for safety management personnel of hazardous chemical business units in 2022
Go crawler framework -colly actual combat (I)
The picture of wechat official account can not be displayed normally
我想问一下兴业证券怎么开户?通过链接办理股票开户安全吗
实现mnist手写数字识别
Technologie des fenêtres coulissantes en octets dans la couche de transmission
[redis realizes seckill service ②] solution to oversold problem
ros(24):error: invalid initialization of reference of type ‘xx’ from expression of type ‘xx’
Add information on the left and add parts on the right of the status bar
Usage of ViewModel and livedata in jetpack
Working principle analysis of kubernetes architecture core components
Several ways for wechat applet to jump to the page are worth collecting
断言(assert)的用法
Virtual machine - network configuration
108页(4万字)未来公寓智能化设计平台项目方案建议书2022版