Suppose I have:
trait Normalizer[T]{
def apply(x:T):T
}
case class DoubleNormalizer() extends Normalizer[Double] {
def apply(x:Double):Double {
... impl ...
}
}
Does boxing/unboxing happen in either of the following cases, and would @specialized avoid it?
val d1:Normalizer[Double]
val d2:DoubleNormalizer
d1(123.4) // boxes Double? (probably yes because d1.apply(T=Object)
d2(123.4) // boxes Double? maybe not because s2.apply(Double)
Without specialization, does the call to d2.apply receive a Double or an Object?
Feasibly:
the former because the compiler can prove at compile-time, the type of apply method is a double.
the later because DoubleNormalizer.apply(Double) is the implementation of Normalizer.apply(Object), and apply(Object) is the only concrete type signature that the JVM will provide.