I am learning Scala and came across a program where Value s in the program is mentioned just s. I mean it is not println(s) or something else. Why do we mention it like this? What does it do? You can find this in the 10th line of the code below...just s declared as val.If it is supposed to write the value of s, then why don't we use println(s)?
object Main {
class MyString(val jString: String) {
private var extraData = ""
override def toString = jString + extraData
}
object MyString {
def apply(base:String, extras:String) {
val s = new MyString(base)
s.extraData = extras
s
}
def apply(base:String) = new MyString(base)
}
def main(args: Array[String]) {
println(MyString("hello", "world"))
println(MyString("hello"))
}
}