How to get Ponter/Reference semantics in Scala
问题 In C++ I would just take a pointer (or reference) to arr[idx]. In Scala I find myself creating this class to emulate a pointer semantic. class SetTo (val arr : Array[Double], val idx : Int) { def apply (d : Double) { arr(idx) = d } } Isn't there a simpler way? Doesn't Array class have a method to return some kind of reference to a particular field? 回答1: Arrays used in Scala are JVM arrays (in 2.8) and JVM arrays have no concept of a slot reference. The best you can do is what you illustrate.