我得到了这种情况我无法理解阴影.例如以下代码
class Foo {
int a = 5;
void goFoo(int a) {
// No problem naming parameter as same as instance variable
for (int a = 0; a < 5; a++) { }
//Now the compiler complains about the variable a on the for loop
// i thought that the loop block had its own scope so i could shadow
// the parameter, why the compiler didnt throw an error when i named
// the parameter same as the instance …Run Code Online (Sandbox Code Playgroud) 我能够使用Java语言做一些实验,令人惊讶的是我开始使用这行代码{{ }}.更多我已经注意到使用该代码结构,我可以使用该类的任何方法而无需为其创建对象变量.
例如:
class Sample {
public void hello() {
// Do something here.
}
}
class SampleTest {
public void testHello() {
new Sample {{ hello(); }};
}
// PSVM ...
}Run Code Online (Sandbox Code Playgroud)
问题是第8行的陈述所要求的概念/术语是什么?