有沒有更好的方法來重寫這些多載的方法來避免這個double definition問題?
def test(a: Option[Int]) {
println(a)
}
def test(a: Option[String]) {
println(a)
}
test(Some(1))
test(Some("1"))
示例 -> https://scastie.scala-lang.org/3V57pKeATFSmMNnDV2xBxA
uj5u.com熱心網友回復:
使用多型方法:
def test[T](a: Option[T]): Unit = {
println(a)
}
test(Some(1))
test(Some("1"))
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/377862.html
標籤:斯卡拉
