jeudi 29 septembre 2016

Java: IDE indicates that my if else statement is redundant and I need an explanation to why

I am a beginner in programming. The Netbeans IDE is indicating that this if-else statement is redundant:

public boolean x = false;

private void add_labelMouseClicked(java.awt.event.MouseEvent evt) {                                       

    jPanel2.setVisible(x);
        if(x==false){
            x=true;
        }else
            x=false;
}         

And if I correct this if-else statement using the IDE it turns the code into this:

public boolean x = false;

private void add_labelMouseClicked(java.awt.event.MouseEvent evt) {                                       

    jPanel2.setVisible(x);
       x = x == false;
} 

I need a simple explanation on the second code and how come it has a similar function to the first code. Sorry for my bad English.

Aucun commentaire:

Enregistrer un commentaire