Reputation: 1007
How to change all variable with scala type (like Boolean) to java type (like java.lang.Boolean
). Because when using scala type I get an error:
That is dissapear when I change to java type:
But I dont want to typing all variable with scala Boolean
sepecification to java.lang.Boolean
because that too long. Whereas scala IDE automatically assume variabel declared with Boolean
is a scala type. I mean is there any shortcut for this. For example in python there are something like import A.B.C as initial1
. Or Is possible to change default variable declaration from scala type to java type in eclipse IDE.
And then why that error occur? I write this snippet:
object CompatibleTest extends App{
println("test compatible")
val m = new java.lang.Boolean(true)
if(m.isInstanceOf[Boolean]) println("yes... ")
}
that indicate both java.lang.Boolean
and scala Boolean
are the same type.
Upvotes: 0
Views: 65
Reputation: 167901
You can
import java.lang.{Boolean => jBoolean}
to save typing. Shadowing the Scala Boolean
with Java's is not likely to work out well for you.
Note also that Scala boxes its Boolean
(which is Java's primitive boolean
) into java.lang.Boolean
in generic code and a few other contexts, including isInstanceOf
tests.
Upvotes: 1