Scala runs on the JVM and is based on the Java library.
The scala file (*. Scala ) will be compiled into the bytecode of the java class and run them in the JVM . for your example:
object A{ val arg1=1 def myFun(arg2:Int)=arg1 }
will be translated to (decompile bytecode by javap):
public class A$ extends java.lang.Object{ public static final A$ MODULE$; private final int arg1; public static {}; public int arg1(); public int myFun(int); public A$(); }
class A{ val arg1=1 def myFun(arg2:Int)=arg1 }
will be translated to (decompile bytecode by javap):
public class A extends java.lang.Object{ private final int arg1; public int arg1(); public int myFun(int); public A(); }
trait A{ val arg1=1 def myFun(arg2:Int)=arg1 }
will be translated to (decompile bytecode by javap):
public interface A{ public abstract void $line5$$read$A$_setter_$arg1_$eq(int); public abstract int arg1(); public abstract int myFun(int); }
so for your other memory issues, I think this is the same as Java .
chengpohi
source share