相关疑难解决方法(0)


Scala双重定义(2种方法具有相同类型的擦除)

我在scala中写了这个,它不会编译:

class TestDoubleDef{
  def foo(p:List[String]) = {}
  def foo(p:List[Int]) = {}
}
Run Code Online (Sandbox Code Playgroud)

编译通知:

[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
Run Code Online (Sandbox Code Playgroud)

我知道JVM没有对泛型的原生支持,所以我理解这个错误.

我可以写包装List[String],List[Int]但我很懒:)

我很怀疑,但是,有没有另一种方式表达List[String]不是同一种类型List[Int]

谢谢.

scala overloading compilation typeclass type-erasure

67
推荐指数
6
解决办法
1万
查看次数