Scala case match default value

前端 未结 3 1230
你的背包
你的背包 2021-01-31 08:30

How can I get the default value in match case?

//Just an example, this value is usually not known
val something: String = \"value\"

something match {
    case \         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-31 08:47

    here's another option:

    something match {
        case "val" => "default"
        case default@_ => smth(default)
    }
    

提交回复
热议问题