Access first default parameter value while supplying the rest
Given:
case class Person(name:String = "Bob", age:Int = 20)
How can I accept the default value for name while supplying the age?
Eg. I can do 开发者_JAVA技巧this:
Person() -> Person("Bob", 20)
Person("Jim") -> Person("Jim", 20)
How can I do this:
Person(,35) -> Person("Bob", 35)
You can use named parameters with default values:
case class Person(name: String = "Bob", age: Int = 20)
Person(age = 23)
精彩评论