案例对象和对象的区别 [英] Difference between case object and object
本文介绍了案例对象和对象的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
scala 中 case 对象和对象有什么区别吗?
Is there any difference between case object and object in scala?
推荐答案
案例类与常规类的不同之处在于:
Case classes differ from regular classes in that they get:
- 模式匹配支持
equals
和hashCode
的默认实现- 序列化的默认实现
toString
的更漂亮的默认实现,以及- 他们从
scala.Product
自动继承的少量功能.
- pattern matching support
- default implementations of
equals
andhashCode
- default implementations of serialization
- a prettier default implementation of
toString
, and - the small amount of functionality that they get from automatically inheriting from
scala.Product
.
模式匹配、equals 和 hashCode 对单例并不重要(除非你做一些真正退化的事情),所以你几乎只是获得序列化,一个很好的 toString
,以及一些你需要的方法可能永远不会用了.
Pattern matching, equals and hashCode don't matter much for singletons (unless you do something really degenerate), so you're pretty much just getting serialization, a nice toString
, and some methods you probably won't ever use.
这篇关于案例对象和对象的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文