当使用null调用toFloat时,该程序应该避免使用null.但是我还在接受NPE ......任何帮助
System.out.println(toFloat(null, null));
private static Float toFloat(Float def, String str) {
try {
return str != null ? Float.parseFloat(str) : def;
} catch (NumberFormatException e) {
return def;
}
}
Run Code Online (Sandbox Code Playgroud)