2 ms·
You're not supposed to, but I've certainly found code out there that does use == to compare boxed integers because the test cases they used happen to work. And
by monocasa 3y ago
You're not supposed to, but I've certainly found code out there that does use == to compare boxed integers because the test cases they used happen to work.
And in fact when I googled to find the exact range where it switches from cached integers to truly creating new objects, the top link was at best highly misleading. https://www.tutorialspoint.com/check-two-numbers-for-equality-in-java https://www.tutorialspoint.com/check-two-numbers-for-equalit...