I was executing the following codes, got some unexpected results
class Test { public static void main(String[] args) { Short i = 122, j = 122; if (i == j) { System.out.println("true"); } else { System.out.println("false"); } } }
and
class Test { public static void main(String[] args) { Short i = 1222, j = 1222; if (i == j) { System.out.println("true"); } else { System.out.println("false"); } } }
When I executed this code, the first code gives true output, and the second code gives false output. I know when we compare objects using == , it does not look for actual values, but simply compares the links. But in the first case, he compares the values, and in the second - no.
java
user2797512
source share