A extends B written A<:B in scala not A>:B
by the way, a system like scala is powerful enough to avoid using Object (AnyRef in scala) in your code
package v6ak.util import java.util.Comparator class NaturalComparator[T <: Comparable[T]] extends Comparator[T] { override def compare(o1: T, o2: T) = { if (o1 == null || o2 == null) { throw new NullPointerException("Comparing null values is not supported!"); } o1.compareTo(o2); } } object StringComparator extends NaturalComparator[String] object Examples { StringComparator.compare("a", "b") StringComparator.compare(2, "b")
shellholic
source share