为什么我this在变量声明中使用引用时,不会出现非法前向引用?this声明有和没有它有什么区别?
以下示例由于非法前向引用而无法编译:
class FailsToCompile {
int a = b; //illegal forward reference
int b = 10;
}
通过限定编译错误的使用b就this消失了。
class Compiles {
int a = this.b; //that's ok
int b = 10;
}
有只小跳蛙
蓝山帝景
随时随地看视频慕课网APP
相关分类