vendredi 28 septembre 2018

Is 'error: variable a might not have been initialized' really necessary in this if construct?

How do I tell Java that I don't need to initialize a to have a working program and to not give me an error?

int a;
boolean b = true;
while (true) {
   if (b == false) {
       System.out.print(a);
       break;
   } else {
       b = false;
       a = 5;
   }
}

And if I can't, is there a reason why this is the way the compiler was designed?

Was it easy to design such a compiler or is this a mechanism to ensure that I restructure my code?

This is not the same question as this one

Aucun commentaire:

Enregistrer un commentaire