【发布时间】:2012-12-15 11:40:16
【问题描述】:
这不会编译并给出以下错误:Illegal start of expression。为什么?
public static AppConfig getInstance() {
return mConfig != null ? mConfig : (throw new RuntimeException("error"));
}
【问题讨论】:
-
因为
throw不是表达式 -
"return (throw new RuntimeException("error"));" - 你不能返回一个 throw new exception()
-
空对象模式在这里值得一提。