-1

Why it is possible to create instance of a case class in scala without new operator?

misza222
  • 393
  • 3
  • 15

1 Answers1

2

Try this.

class C(arg: Int)
object C {
  def apply(i: Int): C = new C(i)
}

val c = C(99)

A case class automatically creates the companion object with the factory method via apply().

jwvh
  • 50,871
  • 7
  • 38
  • 64