views:

44

answers:

1

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

+2  A: 

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
Correct. As thus, this is not a Netbeans issue, it is a user-issue.
WebDevHobo
just to confirm, then why does the step over from var4.add(var); go to var4.add(var); inside the else part?
Ajay
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