my env is :
Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
watch this example first:
scala> var a = 1
a: Int = 1
scala> var c = 'c
c: Symbol = 'c
scala> var d = 1.1
d: Double = 1.1
scala> var b = "123"
b: java.lang.String = 123
scala> val e:String = "234"
e: String = 234
so, you can see the other literal except string, the default type are Scala Types(Int Double Symbol.
but the string literal is Java type.(java.lang.String
and when you define a value with the scala type String, the String literal will be the type Scala String.
why the string literal’s default type isn’t Scala String?
Second:
when you must call scala method from java.
and your scala method with Parameter like this:
def hello(i:Int) = {
println(i)
}
on java side . if you call like this.
object.hello(null)
it will fail by type mismatch.
the java.lang.Integer can be null. but the scala Int can’t be null.
null in scala is the subtype of AnyRef. not AnyVal..
i found that AnyRef and AnyVal take me to the java1.4 world, which dose not have autobox.. .
Answer to your first question:
scala.Stringis simply a type synonym defined inPreludePredeffor good oldjava.lang.String. (Unlikescala.Int,scala.Floatetc. which are distinct types fromjava.lang.Integer,java.lang.Floatetc.)This might help: (Observe the types.)