标签:
new
keyword, just access the object directly by name. NOTE: Because the companion object and the class must be defined in the same source file you cannot create them in the interpreter.
Case classes differ from regular classes in that they get:
equals
and hashCode 默认实现equals和hashCode
toString
, and 默认更好实现toStringscala.Product
.NOTE: 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.
标签:
原文地址:http://www.cnblogs.com/qingwen/p/5160909.html