Skip to content

Instantly share code, notes, and snippets.

@jiamingd
Created July 14, 2017 05:01
Show Gist options
  • Save jiamingd/2a033b412f0a8ab1535aeb573a582591 to your computer and use it in GitHub Desktop.
Save jiamingd/2a033b412f0a8ab1535aeb573a582591 to your computer and use it in GitHub Desktop.
Fun playing with case class constructor overload
case class Car(color: String, size : Int, door : Int){
def this(door : Int) = this("silver", 6, door)
}
object Car{
def apply(door : Int ) = new Car(door)
}
val coupe = Car(2)
val car = Car("red", 8, 4)
@jiamingd
Copy link
Author

Meaning Car(2) will not be a real case class contructor ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment