Double Literally Result False [duplicate]

别等时光非礼了梦想. 提交于 2019-12-13 03:53:20

问题


My Question about Wrapper classes. Case 1: I'm Declaring two Integer variables and assigning same values 127, and i'm printing both hashCode. It's Generated same hashCode and result will be printed true. But In Case 2: Generated the Same hashCode but result will be printing false. Please Could you relate. Why Printing a false result.

package com.oca.test.exam;

public class TestCasesIntegerAndDouble {

    public static void main(String[] args) {

        //Case 1:
        Integer i1 = 127;
        Integer i2 = 127;

        System.out.println(i1.hashCode()); //127
        System.out.println(i2.hashCode()); //127
        System.out.println(i1 == i2); //true

        //Case 2:
        Double d1 = 127.0;
        Double d2 = 127.0;

        System.out.println(d1.hashCode());//1080016896
        System.out.println(d2.hashCode());//1080016896
        System.out.println(d1 == d2); //false
    }
}

来源:https://stackoverflow.com/questions/54918661/double-literally-result-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!