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)

リストとシーケンス

参照なし

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)

マップとセット

引用

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)

おすすめ

転載: blog.csdn.net/jklcl/article/details/84980261