from time to time, i deal with java that has stuff like the following in it:
def printDbl(d:Double) { println("dbl: " + d) } def printInt(i:Int) { println("int: " + i) } naturally, i'd like to wrap this in some scala, which ends up looking like this:
def print[T:Manifest] (t:T) { if (manifest[T] <:< manifest[Int]) { printInt(t.asInstanceOf[Int]) ; return } if (manifest[T] <:< manifest[Double]) { printDbl(t.asInstanceOf[Double]) ; return } throw new UnsupportedOperationException("not implemented: " + manifest[T]) } but when i run the following, i get a runtime exception:
print(1) print(2.0) print("hello") i seem to recall there being a way to catch this at compile time, but i can't seem to google it up. perhaps some clever implied conversions?