Differences between case object T and case class T() when defining ADT?
问题 Let's say in scala I have an ADT as follows: sealed trait Animal object Animal { case class Lion(name: String) extends Animal case class Elephant(name:String) extends Animal case object Tiger extends Animal } Here, is it preferable to declare Tiger as a case object or should it be declared as an empty case class i.e case class Tiger() ? Does one have any advantage over other? 回答1: If there is the only Tiger it should be an object. If there can be several equal Tiger s it should be a class.