Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of these Java files in scala.runtime?

There are a few *.java files in the source tree of Scala in the scala.runtime directory.

Those files seem to be very simple, e. g. DoubleRef.java looks like this:

package scala.runtime;

public class DoubleRef implements java.io.Serializable {
    private static final long serialVersionUID = 8304402127373655534L;

    public double elem;
    public DoubleRef(double elem) { this.elem = elem; }
    public String toString() { return java.lang.Double.toString(elem); }
}

Is there any reason why those classes can't be defined in Scala?

like image 864
soc Avatar asked Sep 11 '11 21:09

soc


1 Answers

Just a guess, too: there is no Scala construct that compiles to a public field — public vars in Scala compile to a private field and to a public accessor and mutator. As I imagine that those *Ref classes are used extensively, this could be an optimization to avoid frequent method calls and replace them with direct field access.

like image 114
Jean-Philippe Pellet Avatar answered Oct 22 '22 06:10

Jean-Philippe Pellet