0

What is the difference between these two cases? Would the equality check be wrong? If not, which one is faster?

Gouz
  • 336
  • 1
  • 6
  • 19

1 Answers1

-1

If you use wrapper class (Byte instead of byte), you should use equals method. The code below doesn't work (not likely to happen) as == compare reference not the value.

public static void main(String[] args) {
    Byte b1 = new Byte((byte) 0);
    Byte b2 = new Byte((byte) 0);
    System.out.println(b1 == b2);
}

Some explanation here.

Cyril G.
  • 1,879
  • 2
  • 5
  • 19