You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But it wastes memory since it creates three fields in byte codes:
public classFoo implements scala.ScalaObject {
privatefinal scala.Function0<java.lang.String> p;
private java.lang.String p2;
public volatile int bitmap$0;
public java.lang.String p2();
public Foo(scala.Function0<java.lang.String>);
}
I suggest that scalac automatically generate code for class Foo(lazy val p: String) like this:
public classFoo implements scala.ScalaObject {
private scala.Function0<java.lang.String> p2;
public scala.Function0<java.lang.String> p2();
public void p2_$eq(scala.Function0<java.lang.String>);
public Foo(scala.Function0<java.lang.String>);
}
And it even a little faster than lazy val, since it omits checking if the field initialized or not.
The text was updated successfully, but these errors were encountered:
Currently, this is not allowed:
Although I can create another lazy val like this:
But it wastes memory since it creates three fields in byte codes:
I suggest that scalac automatically generate code for
class Foo(lazy val p: String)
like this:This approach creates only one field:
And it even a little faster than
lazy val
, since it omits checking if the field initialized or not.The text was updated successfully, but these errors were encountered: