尝试编译以下内容时
public class Test {
public void method(String foo) {
// This compiles if the curly braces are uncommented
if(foo instanceof Object) // {
Object bar = (Object) foo;
// }
}
}
我收到以下错误
javac -Xlint:all Test.java
Test.java:5: error: not a statement
Object bar = foo;
^
Test.java:5: error: ';' expected
Object bar = foo;
^
2 errors
为什么Object bar = (Object) foo;
代码需要在一个块中才能编译?