I started studying recently Scala. And I don't understand why this code is not working. Can anybody help me?
import scala.collection.mutable
import scala.collection.mutable.Map
class Bijection[T] (val v: Set[T]) {
private var addition = 0
private var reversed = false
def add(i: Int)(implicit ev: T <:< Int) = {
addition += i
}
def reverse(implicit ev: T <:< String) = {
reversed = !reversed
}
}
object Bijection {
def apply(s: Set[String]): Bijection[String] = {
println("Hello string")
Bijection(s)
}
def apply[T](s: Set[T]): Bijection[T] = {
println("Hello T")
Bijection(s)
}
}
object Main {
def main(args: Array[String]): Unit = {
var x = Bijection[String](Set[String]("fd", "fasf"))
}
}
This code should print "Hello" But I get now next trace.
Error:(23, 7) double definition:
def apply(s: Set[String]): Bijection[String] at line 18 and
def apply[T](s: Set[T]): Bijection[T] at line 23
have same type after erasure: (s: scala.collection.immutable.Set)Bijection
def apply[T](s: Set[T]): Bijection[T] = {