0

I am debugging the following lines of code


    if (var.getvar2() != var3) {
           var4.add(var);
    } else {
           isNeeded= true;
           if (incomingPublishedDate.compare(modifiedDate) < 0) {
               importNeeded = true;
           } else {
               var4.add(var);
           }
   }

Here var.getvar2() and var3 are of type Long. While debugging, when the condition goes like

10000 != 10000

the if should evaluate to false. But from the first if, the next Step Over goes to

var4.add(var);

and the next Step Over goes to var4.add(var);

Is this a Netbeans bug? Or is it with the Long comparision.

I am using Netbeans IDE 6.5

Zed
  • 57,028
  • 9
  • 76
  • 100
Ajay
  • 7,378
  • 18
  • 57
  • 75

1 Answers1

2

You cannot compare objects by value. That comparison would only be true if the two references compared refer to the same object. Instead use:

if (! var.getvar2().equals(var3)) {
   ...
}
Zed
  • 57,028
  • 9
  • 76
  • 100
  • Correct. As thus, this is not a Netbeans issue, it is a user-issue. – KdgDev Aug 26 '09 at 07:50
  • just to confirm, then why does the step over from var4.add(var); go to var4.add(var); inside the else part? – Ajay Aug 26 '09 at 08:31
  • Oh I see what the real problem is. Add some dummy System.out.println("blah"); lines below both adds, and see if they are actually called by the code. Or copy in the whole function body, you might have a problem with your opening/closing brackets (I don't see how though). – Zed Aug 26 '09 at 08:38