This code
class Foo(str: String) {
val len = str.length
def getLen = len
def getStr = str}
will be compiled to
public class Foo implements ScalaObject
{
private final int len;
private final String str;
public Foo(String str)
{
this.str = str;
super();
len = str.length();
}
public String getStr()
{
return str;
}
public int getLen()
{
return len();
}
public int len()
{
return len;
}
public int $tag()
throws RemoteException
{
return scala.ScalaObject.class.$tag(this);
}
}
But this code
class Foo(str: String) {
val len = str.length
def getLen = len
}
will be compiled to
public class Foo implements ScalaObject
{
private final int len;
public Foo(String str)
{
len = str.length();
}
public int getLen()
{
return len();
}
public int len()
{
return len;
}
public int $tag()
throws RemoteException
{
return scala.ScalaObject.class.$tag(this);
}
}
Why there is no private member in class Foo?
private final String str;
Is it some sort of optimization?
Why it is allowed to point to constructor's parameters.
Why there is no compile-time error for line "def getStr = str
"?