Created
July 14, 2017 05:01
-
-
Save jiamingd/2a033b412f0a8ab1535aeb573a582591 to your computer and use it in GitHub Desktop.
Fun playing with case class constructor overload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Meaning Car(2) will not be a real case class contructor ?