In addition to “because of autoboxing,” you can watch what magic is used.
-Xprint:all will show what phase the compiler did the magic.
-Ytyper-debug shows what decisions typer made.
For example, if val a: Int , then val b = a.isInstanceOf[AnyRef] changes to Int.box(a).$asInstanceOf[Object] in erasure, where $asInstanceOf is the nominal member of Object .
There is a good comment about these transformations in erasing :
/** Replace member references as follows: * * - `x == y` for == in class Any becomes `x equals y` with equals in class Object. * - `x != y` for != in class Any becomes `!(x equals y)` with equals in class Object. * - x.asInstanceOf[T] becomes x.$asInstanceOf[T] * - x.isInstanceOf[T] becomes x.$isInstanceOf[T] * - x.isInstanceOf[ErasedValueType(tref)] becomes x.isInstanceOf[tref.sym.tpe] * - xm where m is some other member of Any becomes xm where m is a member of class Object. * - xm where x has unboxed value type T and m is not a directly translated member of T becomes T.box(x).m * - xm where x is a reference type and m is a directly translated member of value type T becomes x.TValue().m * - All forms of xm where x is a boxed type and m is a member of an unboxed class become * xm where m is the corresponding member of the boxed class. */
In contrast, the conversion due to the link mentioned in the OP error message is due to implicit in Predef :
scala> val I: java.lang.Integer = a [[syntax trees at end of typer]] // <console> private[this] val I: Integer = scala.this.Predef.int2Integer($line3.$read.$iw.$iw.a);
source share