I am a Scala newbie. I've ploughed through a couple of books, and read some online tutorials. My first project is having problems, so I have reduced the code to the simplest thing that can go wrong.
I've searched google and stack overflow for scala/constructors/varargs, and read a couple of tours of scala.
The (nearly) simplest code is:
class Foo(val params: Int*)
case class Foo1(val p: Int) extends Foo(p)
case class Foo2(val p1: Int, val p2: Int) extends Foo(p1, p2)
object Demo extends App {
override def main(args: Array[String]) {
val f = Foo2(1, 2)
f.p1
}
}
The exception occurs when accessing p1 and is
Exception in thread "main" java.lang.ClassCastException: scala.collection.mutable.WrappedArray$ofInt cannot be cast to java.lang.Integer
Resorting to debugging using eclipse, I found an interesting property: When looking at variables
f Foo2 (id=23)
p2 2
params WrappedArray$ofInt (id=33)
array (id=81)
[0] 1
[1] 2
So what happened to p1?
I'm sorry for troubling you with a newbie question