Tuesday, May 15, 2012

Java 5 autoboxing fail on equality check

  Double d1 = 25d;
  Double d2 = 25d;

  if (d1 == d2) {
            System.out.println("equal (==)");
  } else if (d1.equals(d2)) {
            System.out.println("equal (using equals() method)");
  }

The output is:
equal (using equals() method)

No comments:

Post a Comment