gku*_*ar7 3 java aop javac runtimeexception
为什么这不编译(尝试使用java 8和java 10)?它会产生一个缺少的返回语句错误.
public class CompilerIssue {
public boolean run() {
throwIAE();
// Missing return statement
}
public void throwIAE() {
throw new IllegalStateException("error");
}
}
Run Code Online (Sandbox Code Playgroud)
你的方法有一个返回类型,所以它应该返回一个布尔结果.
public boolean run() {
throwIAE();
// Missing return statement
return false;
}
Run Code Online (Sandbox Code Playgroud)
或者你应该直接在方法中抛出异常:
public boolean run() {
throw new IllegalStateException("error"); // it will compile
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
188 次 |
| 最近记录: |