What is the difference between these two cases? Would the equality check be wrong? If not, which one is faster?
Asked
Active
Viewed 100 times
0
-
1You understand the difference between a primitive value (non-object) and an object instance? – Thorbjørn Ravn Andersen Feb 06 '21 at 13:22
-
It's the basic understanding of OOPL in general, and JAVA in particular. – Feb 06 '21 at 13:49
-
1But where is performance discussed in the "duplicated" one? – Gouz Feb 06 '21 at 15:18
-
@ThorbjørnRavnAndersen @Joe I'm not sure what this has to do with anything, since `Byte.compare` (and any other `
.compare` method) is `static` and should be invoked with primitive types as arguments. – Erwin Bolwidt Feb 07 '21 at 21:47
1 Answers
-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