Why does the case class in Scala needs to have compulsory parenthesis().
case class TestCase() {}
Why it cannot be like below:
case class TestCase {}
Why does the case class in Scala needs to have compulsory parenthesis().
case class TestCase() {}
Why it cannot be like below:
case class TestCase {}
This is to avoid mistakes.
If you have a case class without args it means all case classes that you create will be identical so in most cases what you really mean is to do case object
As case classes are the special classes, which has already defined factory methods. One of factory method is apply function(that construct the object of case class, without new keyword). Because of this apply methods functionality, we have to specify the parenthesis, which means there are no arguments to be pass in apply method and the default apply method(Without any parameters) has to be called to construct the object of that case class.