I'm quite new to Scala (2.8) and here's something that I'm struggling to express in Scala:
I need to define a class that (due to interoperability with a Java library) implements Comparable; its generic type has to be Comparable with itself or a superclass
I also need to have a no-args constructor along with another that makes use of the generic parameter
I wrote a simple equivalent of what I'm trying to get in Java:
public class MyComparable<T extends Comparable<? super T>>{
public MyComparable() {}
public MyComparable(T a){
System.out.println(a);
}
}
I can import without any problem this class in the scala REPL and instantiate it.
This is what I'm writing in Scala to try to accomplish the same thing:
import java.lang.Comparable
class MyComparable[T <: Comparable[_>:Tb],Tb]()(implicit ev: T=:=Tb) {
def this(a: T) = {
this()
println(a)
}
}
I tried both by using the no-args constructor as the default one, or using the one with the T argument: in both cases I get error: could not find implicit value for parameter ev: =:=[T,Tb]
at line 5
Afaik, =:= is imported by default from scala.Predef (and in fact, this code works fine with only one constructor)