mardi 27 janvier 2015

Why Double.parseDouble("ABC") not returns Double.NaN?


This code:



Double.parseDouble("ABC")


throws a NumberFormatException.


Why is it wrong to expect a Double.NaN (NaN is literally Not-A-Number).


A working example is this:



public static void main(String[] args) {
System.out.println("Is ABC a number? " + Double.isNaN(Double.parseDouble("ABC"));
}


I expect Is ABC not a number? true as output.


Why must this be an Exception?





Aucun commentaire:

Enregistrer un commentaire