'Why is 5.0 == 5? [duplicate]
public void inherits(){
Integer x = 5;
double y = 5.0;
Integer y2 = new Integer((int)y);
if(x==y){
System.out.println("A");
}
if(x.equals(y)){
System.out.println("B");
}
}
Why does this print A and not B? how is 5.0 == 5?, one is a double, the other an int
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
