Case Class

Case classes are used to conveniently store and match on the contents of a class. You can construct them without using new.

Define

case class Customer(cid: Int, name: String, address:String)

Usage

val customerA = Customer(1, "Robin", "Taipei")
val customerB = Customer(2, "Jiaming", "Kaohsiung")
val customerC = Customer(3, "Lin", "Pentung")

Output

println(List(customerA, customerB, customerC)) //List(Customer(1,Robin,Taipei), Customer(2,Jiaming,Kaohsiung), Customer(3,Lin,Pentung))
println(customerA.name) // Robin

Moreover

println(customerA == customerB) // false