mardi 16 février 2021

Comparing Integers in Java using .equals produces incorrect result [closed]

Both the debugger and the compiled app are evaluating this IF statement as true:

    public Boolean GetStatusHasBeenChanged() {
        int intStatus = 7;
        int intStatusUnknown = 999;
        if (intStatus == intStatusUnknown) {
            //code here is reached and executed
        }
        ...
    }

Amazingly, the IDE warns that this if statement will always be false. Yet it evaluates to true at runtime.

Aucun commentaire:

Enregistrer un commentaire