There are plenty of == errors in production Java code.  Remember that not
everyone studied Java, or listened, so they will learn on the job, and even
if they've already learned before writing the code they don't always get it
right.  The last time I saw an == bug was on Wednesday.

Having an IDE actually highlight those things saves me so much time in
working out why on earth certain bugs exist.  We can all learn all the
corner cases of all the languages, but even when you know them you don't
want to have to think about them constantly while reading unfamiliar code.

Also, knowing that Integers are objects isn't the problem, it's that ==
succeeds sometimes.  Integer x = 100, y = 100; x == y gives true.  replace
the 100s with 400 and you get false.  So if you don't know how autoboxing
works you might test with 100 and assume that autoboxing affects == (it
does, but not when both sides are already reference types) and later see a
bug because of a higher value.

On Sat, Mar 10, 2012 at 5:53 PM, Jon Kiparsky <[email protected]>wrote:

> If an IDE is a way to avoid knowing the language, or to avoid
> understanding your own code, I'd rather avoid the IDE.
> A student who doesn't know that an Integer is an object needs a kicking,
> not a safety net.
> (I say a student, assuming that nobody could possibly be working as a
> programmer and make this mistake... if I'm wrong, I'm sure I'll read about
> it on the Daily WTF, no need to make me sad by robbing me of my comforting
> illusions on a nice Saturday like this one)
>
>
> On Sat, Mar 10, 2012 at 3:46 PM, Ricky Clarkson 
> <[email protected]>wrote:
>
>> [image: Inline image 1]
>>
>> Use a decent IDE and/or static analysis tool, and stop worrying.
>>
>> On Sat, Mar 10, 2012 at 5:41 PM, Vineet Sinha <[email protected]>wrote:
>>
>>> I just read about this blog post that might be worth pointing out:
>>> http://www.tomhalligan.co.uk/category/technology/programming/
>>>
>>> The summary: be careful when using '==' with Integers (as opposed to
>>> ints).
>>>
>>> The problem is sometimes hard to diagnose because Java caches Integer
>>> objects from -128 to 127. I remember reading about this when I first
>>> started playing with Autoboxing, but this is one of those small details
>>> that it is easy to forget.
>>>
>>> Regards,
>>> Vineet
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "The Java Posse" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/javaposse?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "The Java Posse" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/javaposse?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

<<equals.png>>

Reply via email to