Этот код
class Foo(str: String) {
val len = str.length
def getLen = len
def getStr = str}
будет скомпилировано в
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);
}
}
Но этот код
class Foo(str: String) {
val len = str.length
def getLen = len
}
будет скомпилировано в
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);
}
}
Почему в классе Foo нет закрытого члена?
private final String str;
Это какая-то оптимизация?
Почему разрешено указывать на параметры конструктора.
Почему нет ошибки времени компиляции для строки "def getStr = str
"?