Scala references

Common data type

No reference

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 and Seq

No reference

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 and Set

Quoted

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)

Guess you like

Origin blog.csdn.net/jklcl/article/details/84980261