fork download
  1. object Main {
  2. def cast[A](x: Any) = x.asInstanceOf[A]
  3.  
  4. def main(args: Array[String]): Unit = {
  5. println(cast[Long](9).getClass())
  6. println(cast[String](9).getClass())
  7. }
  8. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.scala:5: error: type mismatch;
 found   : Long
 required: ?{val getClass: ?}
Note: primitive types are not implicitly converted to AnyRef.
You can safely force boxing by casting x.asInstanceOf[AnyRef].
    println(cast[Long](9).getClass())
                      ^
one error found
stdout
Standard output is empty