0
public class NewClass
 {
 public static void main(String args[]) {
      Integer a = 188;
      Integer b = 188;
      System.out.println(a.intValue() == b); //prints true
   }
}

The above code sample prints true. Since I've not considered the integer value for 'b', How is the code compared and TRUE was printed?

GhostCat
  • 137,827
  • 25
  • 176
  • 248
cosmos713
  • 87
  • 3
  • 7
  • 1
    `intValue()` returns `int` and from what I remember `int==Integer` or `Integer==int` is unboxed to `int==int`. – Pshemo Apr 22 '17 at 19:44
  • @GhostCat Found better duplicate. Like always it is good to search [among Jon's answers](https://stackoverflow.com/search?q=user%3A22656+%5Bjava%5D+unboxed) :) – Pshemo Apr 22 '17 at 19:52
  • You still got the deserved upvote. And an extra badge (unless I miscalculated) for linking to a Skeet answer:-) – GhostCat Apr 22 '17 at 19:58
  • 1
    @GhostCat Thx. Sometimes I wish there ware small voting arrows for duplicate link. People could use them to vote if duplicate was correct or not. This would let people show some appreciation toward person who proposed this duplicate (not much to not abuse the system, maybe like edits +2/-2). Hopefully people would be more willing to search for duplicates then. – Pshemo Apr 22 '17 at 20:09
  • Sounds like a good idea to me. – GhostCat Apr 23 '17 at 03:41

0 Answers0