我用 scala 编写的这个程序无法编译:
class TestDoubleDef{
def foo(p:List[String]) = {}
def foo(p:List[Int]) = {}
}
编译器通知:
[error] double definition:
[error] method foo:(List[String])Unit and
[error] method foo:(List[Int])Unit at line 120
[error] have same type after erasure: (List)Unit
我知道 JVM 不支持泛型,所以我理解这个错误。
我可以为 List[String]
和 List[Int]
编写包装,但我很懒:)
我表示怀疑,但是,有没有其他表达 List[String]
和 List[Int]
不同类型的方法?
谢谢。