Java Minutiae - Reflex
Pop QuizThe following is a method from a very decent implementation of Java SE. I've substituted x and y for the actual method name and parameter type. What are the values of x and y ?
public static boolean x(y z) {
return z != z;
}
PS - it's a reasonable method. it may take you a few minutes to come up with the answer.
Show Answer
x = isNaN, y = float
It turns out that
Float.NaN != Float.NaN
. Weird! The same is true for Double.NAN
. Since they're the only values with this property, testing for a lack of reflexivity uniquely identifies these values.