HOW AUTOBOXING IS GOING HERE?

ezra heywood

Total Post:145

Points:1019
Posted by  ezra heywood
Java 
 634  View(s)
Ratings:
Rate this:
Hi there 

This is my code 

public class Autoboxing {
     
     
    public static void main(String[] args) {
 
               double x2 = 0.0/0.0, y2 = 0.0/0.0;
            Double a2 = x2, b2 = y2;
            StdOut.println(x2 == y2);
            StdOut.println(!a2.equals(b2));
    }
 
}

its Output is :
false 
false 

I am expecting 
true 
false
  1. Mayank Tripathi

    Post:397

    Points:3117
    Re: How Autoboxing is going here?

    I think it's something to do with the special value which you get when you divide zero by zero as double values

    Because there are two different flavours of NAN, Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY 
    You can’t directly compare == Double.NAN to check for NAN. However, you can directly compare == Double.NAN; 
    However, you can use Double.isNaN or == to compare with Double.POSITIVE_INFINITY.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!