These java files are in scala What is the purpose in runtime?

In scala In the runtime directory, there are some * in the scala source tree Java file

Those files seem simple, G. doubleref Java is as follows:

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 these classes cannot be defined in scala?

Solution

It's also a guess: no Scala constructs are compiled into public fields – public vars in scala are compiled into private fields and public accessors and mutators I imagine that these * ref classes are widely used, which can be an optimization to avoid frequent method calls and replace them with direct field access

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>