Scala的引用

普通数据类型

无引用

var x = 1
var y = x
y = 2
println(x,"hashCode值:",x.hashCode())
println(y,"hashCode值:",y.hashCode())
//结果
(1,hashCode值:,1)
(2,hashCode值:,2)

List和Seq

无引用

var x: mutable.Seq[Int] = mutable.ListBuffer[Int]()
var y: mutable.Seq[Int] = x
y:+=5
println(x,"hashCode值:",x.hashCode())
println(y,"hashCode值:",y.hashCode())
//结果
(ListBuffer(),hashCode值:,473519988)
(ListBuffer(5),hashCode值:,1669515522)


var x = mutable.Seq[Int]()
var y= x
y:+=1
println(x,"hashCode值:",x.hashCode())
println(y,"hashCode值:",y.hashCode())
//结果
(ArrayBuffer(),hashCode值:,473519988)
(ArrayBuffer(1),hashCode值:,1945410391)

Map和Set

有引用

var x: mutable.Map[String, Int] = mutable.HashMap[String, Int]()
var y: mutable.Map[String, Int] = x
y.put("xx", 2)
println(x,"hashCode值:",x.hashCode())
println(y,"hashCode值:",y.hashCode())
//结果
(Map(xx -> 2),hashCode值:,-463003677)
(Map(xx -> 2),hashCode值:,-463003677)


var x = mutable.HashSet[Int]()
var y= x
y.add(1)
println(x,"hashCode值:",x.hashCode())
println(y,"hashCode值:",y.hashCode())
//结果
(Set(1),hashCode值:,-1075495872)
(Set(1),hashCode值:,-1075495872)

你可能感兴趣的:(大数据)