Sobes.tech
Junior — Senior

How does comparison of primitive int and Integer object work in Java

livecode

Task condition

Code review of a method illustrating the differences when comparing primitive types and object types int and Integer within and outside the cache range.

private static void intPool() {
    int x = 127;
    int y = 127;
    System.out.println(x == y);

    x = 300;
    y = 300;
    System.out.println(x == y);

    Integer objX = 127;
    Integer objY = 127;
    System.out.println(objX == objY);

    objX = 300;
    objY = 300;
    System.out.println(objX == objY);
}