标签:
for(i<-1 to 10){
print(i+",")
}
for(i<-1 until 10){
print(i+",")
}
|
object HelloWorld {
def main(args: Array[String]) {
val s1 = new StringBuilder("abcdefg")
val s2 = new StringBuilder("abcdefg")
println(s1 == s2)//true ->equivalent to java‘s s1.equals(s2)
println(s1 eq s2)//false ->equivalent to java‘s s1==s2
}
}
|
class Marker(val color: String) {
println("creating " + this)
override def toString(): String = "marker color " + color
}
object MarketFactory {
private val markers = Map(
"red" -> new Marker("red"),
"blue" -> new Marker("blue"),
"green" -> new Marker("green")
)
def getMarker(color: String) = if (markers.contains(color)) markers(color) else null
def main(args: Array[String]) {
println(MarketFactory getMarker ("blue"))
println(MarketFactory getMarker ("blue"))
println(MarketFactory getMarker ("red"))
println(MarketFactory getMarker ("red"))
println(MarketFactory getMarker ("yellow"))
}
}
|
标签:
原文地址:http://blog.csdn.net/shijiebei2009/article/details/42968233