I know there are similar posts on the topic, but they don\'t quite address my question. When you do:
Integer a = 10;
Integer b = 10;
System.out.println(\"a =
Your first example is a byproduct of the spec requiring that flyweights be created in a certain range around 0. It should never, ever, be relied on.
As for why Integer doesn't work like String ? I would imagine avoiding overhead to an already slow process. The reason you use primitives where you can is because they are significantly faster and take up way less memory.
Changing it now could break existing code because you're changing the functionality of the == operator.