当我在process()
上添加IntList
时,它会提供运行时" Duplicate field name&signature in class file Cons$3...
"。仅当在函数内定义sealed trait
时才会发生这种情况。
scala> def t4() = {
|
| sealed trait IntList {
| def process (baseCase: Int, f: (Int, Int) => Int): Int =
| this match {
| case End => baseCase
| case Cons(hd, tl) => f( hd, tl.process(baseCase, f))
| }
|
| }
|
| final case object End extends IntList
|
| final case class Cons ( hd: Int, tl: IntList) extends IntList
|
| val l1: IntList = Cons(1, Cons(3, Cons(5, End)))
| }
t4: ()Unit
scala> t4()
java.lang.ClassFormatError: Duplicate field name&signature in class file Cons$3
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at scala.reflect.internal.util.AbstractFileClassLoader.findClass(AbstractFileC
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at Cons$4$.apply(<console>:24)
at .t4(<console>:26)
... 32 elided