开发者

Access first default parameter value while supplying the rest

开发者 https://www.devze.com 2023-01-27 14:45 出处:网络
Given: case class Person(name:String = \"Bob\", age:Int = 20) How can I accept the default value for name while supplying the age?

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消