有没有更好的方法来重写这些重载方法来避免这个double definition问题?
def test(a: Option[Int]) {
println(a)
}
def test(a: Option[String]) {
println(a)
}
test(Some(1))
test(Some("1"))
Run Code Online (Sandbox Code Playgroud)
使用多态方法:
def test[T](a: Option[T]): Unit = {
println(a)
}
test(Some(1))
test(Some("1"))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
125 次 |
| 最近记录: |