Hi I am studying the Advanced Scala book, and I have some trouble understading this piece of code from scalaz source:
object Tag {
/** `subst` specialized to `Id`.
*
* @todo According to Miles, @specialized doesn't help here. Maybe manually specialize.
*/
@inline def apply[@specialized A, T](a: A): A @@ T = a.asInstanceOf[A @@ T]
// ...
}
How can it work? a.asInstanceOf[A @@ T]
should fail with ClassCastException shouldn't it?
An example of usage is:
Multiplication(2) |+| Multiplication(3)
In this case a
is an Int how can it be converted to a @@[Int, Multiplication]
(Tagged[Int, Multiplication]
)
Thanks for the help.