在我目前正在写的程序快速/优雅的方式,我觉得自己做了以下很多...的Java:检查null
Map<String,List<String>> network = loadSerializedObj(file); // null if failed
if(network != null) {
anonNet = util.anonymize(newNet);
} else {
// Some sort of error handling.
System.out.println("Some sort of error message. Exiting...");
System.exit(0);
}
有没有处理的事件更简洁的方式从文件加载序列化对象不起作用,该方法返回null?任何提示都欢迎。任何地方我都可以让这更优雅?
除了检查是否'network'为null,则它在其他地方使用?如果没有,你可以说'if(loadSerializedObj(file)!= null)',它会稍微压缩你的代码。 – mre 2011-04-01 02:21:11