CSC300 / CSC402: Integer Boxing with valueOf [18/24] |
Integer x = Integer.valueOf(30); Integer y = Integer.valueOf(30); x=30, y=30 x==y : true Objects.equals(x,y) : true x.equals(y) : true |
Explicitly calling Integer.valueOf(30)
.
Java will provide the canonical representation for integers close to 0.
The boxed object returned in each case is the same, because 30 is close enough to 0.