The following example assigns a string to a constant: The above example defines the variable In Scala, the type of string is actually Java In Scala But other objects, such as arrays, are mutable objects. Next, we will introduce to you the commonly used ones 8.27.1. Example #
object Test { val greeting: String = "Hello,World!" def main(args: Array[String]) { println( greeting ) } }
greeting is a string constant oftype String(java.lang.String) . String , it doesn’t have its own String class. String is an immutable object, so the object cannot be modified. This means that if you modify the string, a new string object willbe generated. java.lang.String method.