現在、非常によく似たメソッドがいくつかあり、それらを1つのメソッドにマージしたいと思います。これが2つの方法です
def toInt(attrType: String, attrValue: String): Int = {
attrType match {
case "N" => attrValue.toInt
case _ => -1
}
}
def toString(attrType: String, attrValue: String): String = {
attrType match {
case "S" => attrValue
case _ => ""
}
}
ジェネリックを使用してScalaでこれを行う簡単な方法があると思いますか?