开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜