有誰知道爲什麼下面的代碼不會拋出NumberFormatException
?爲什麼可以將此浮點文本值解析爲雙精度值?
public class FlIndeed {
public static void main(String[] args) {
System.out.println(new FlIndeed().parseFloat("0xabcP2f"));
}
public float parseFloat(String s) {
float f = 0.0f;
try {
f = Float.valueOf(s).floatValue();
return f;
}
catch (NumberFormatException nfe) {
System.out.println("Invalid input " + s);
}
finally {
System.out.println("It's time to get some rest");
return f;
}
}
}
注意,有內部.parseFloat("0xabcP2f"));