I am new to scala. I tried this code:
val name = "mike"
println(name.getClass())
Ok and printed java.lang.String
But when I try:
val num = 123
println(num.getClass())
There is such a compiler error:
type mismatch; found : Int required: ?{val getClass: ?} Note: primitive types are not implicitly
converted to AnyRef. You can safely force boxing by casting x.asInstanceOf[AnyRef].
I remember that scala said, "Everything is an object in scala," why can't I call num.getClass()? And how to fix it?
source
share