For a case class, Scala compiler automatically generates many methods including toString() method
scala> // Simple class example scala> class SimpleClass { | } defined class SimpleClass scala> val obj1 = new SimpleClass obj1: SimpleClass = $iwC$$iwC$SimpleClass@26622cf0 scala> obj1.toString() res8: String = $iwC$$iwC$SimpleClass@26622cf0 scala> scala> // Case class example scala> case class MyCaseClass { | } warning: there were 1 deprecation warning(s); re-run with -deprecation for details defined class MyCaseClass scala> val obj2 = MyCaseClass() obj2: MyCaseClass = MyCaseClass() scala> obj2.toString() res9: String = MyCaseClass()
No comments:
Post a Comment