基本上,这就是我想要做的:
ClassName
{
final OtherClass field;
ClassName()
{
field = new OtherClass(this);
}
}
基本上,这就是我想要做的:
ClassName
{
final OtherClass field;
ClassName()
{
field = new OtherClass(this);
}
}
不可能在构造函数体中指定最后一个字段.最后一个字段需要在构造函数主体之前、在初始值设定项列表中或在声明中指定:
class ClassName
{
final OtherClass field = new OtherClass(); // Here
ClassName()
: field = new OtherClass() // or here
{
}
}
由于不能在初始值设定项列表或声明中使用this
,因此不能执行计划中的操作.