I wonder how "==" operator works on primitive values. I understand that "==" checks if two references refers to the same object on heap. But how it works in context of primitive values wihich are stored on stack? e.g
int a = 5;
int b = 5;
I assume that these values aren't stored in the same place in memory but a == b returns "true".
My hypotesis is that JVM treats all values stored in stack as stored in one place in memory and it returns true in case of "==". Could you explain me this matter in a little more detailed way?
Regards
Your hypothesis is wrong. When comparing primitives there are no memory addresses in play. It's a simple instruction to compare whether a value is equal to another value, implemented in bytecode as a comparison (of a register value) and a conditional jump.