I'm trying to overload a constructor in a generic scala class but it's not compiling.
Here's my code:
class V[T](m: Map[T,Double]) {
def this(dt: Seq[Double]) = this(dt.zipWithIndex.map(_.swap).toMap)
}
And the error messages I get:
ERROR: called constructor's definition must precede calling constructor's definition : line 6
ERROR: overloaded method constructor V with alternatives:
(dt: Seq[Double])V[T] <and> (m: Map[T,Double])V[T] cannot be applied to
(scala.collection.immutable.Map[Int,Double]) : line 6
As far as I understand constructor overloading in scala, I think I'm following the proper syntax and the restriction that the call to this should precede everything else.
So what am I doing wrong and how can I fix this?