Sloppy JRE code?

Just looked at setBackground() in JComponent…


public void setBackground( Color bg )
{
    Color oldBg = getBackground();
    super.setBackground(bg);
    if( (oldBg != null) ? !oldBg.equals(bg) : ((bg != null) && bg.equals(oldBg)) )
    {
        repaint();
    }
}

Any idea why you would call bg.equals(oldBg) when you KNOW that oldBg is null and bg is not???

I know this won’t cost much… but it just seems sloppy.

Overly complex C code like this always scares me that I’m missing something in the order or of precedence, but my take is you are right.

My suspicion is that this code probably had multiple authors and was written at multiple times. When the second (or later) author did their work they introduced a redundancy they didn’t realize was there because they didn’t totally grok the original coder’s work.

[quote]Overly complex C code like this…
[/quote]
Ahem… that’s JAVA ;D

Your right. My mistake.

I didn’t know we HAD the trinary operator in Java :slight_smile:

Same observation about overly complex statements though.

[quote]I didn’t know we HAD the trinary operator in Java :slight_smile:
[/quote]
Oh, man, I use it all the time… ;D

Best. Operator. Ever.

System.out.println(“It can be very “+(isTrinaryUseful()?“useful”:“confusing”)+” when building debug strings, so I use it all the time.”);

lol