4 ms·
In my opinion this behaviour shouldn’t be considered strange - “new” always means instantiation of a new object and the “==“ operator for objects always checks
by stygiansonic 7y ago
In my opinion this behaviour shouldn’t be considered strange - “new” always means instantiation of a new object and the “==“ operator for objects always checks for object identity. Since both operands are objects, the above would apply.
This is another reason to avoid boxed primitive whenever possible.
- exabrial 7y agoAgree. The "new" operator in my case was hidden deep inside a corporate framework where the guy that invented it had left a long time ago. Quite an adventure down the rabbit hole to figure that out! Boxed primitives are useful when working with systems and languages where "null" is a concept. Take for example, interacting with a database where you have a boolean column that has true/false/null. That translates well to boxed primitive types.