Warum erkennt Java nicht erreichbaren Code nur im Falle einer while-Schleife? [Duplikat
Diese Frage hat hier bereits eine Antwort:
if (false) vs. while (false): nicht erreichbarer Code vs. toter Code 2 AntwortenWenn ich Code wie @ ha
public static void main(String args[]){
int x = 0;
while (false) { x=3; } //will not compile
}
compiler wird sich beschweren, dassx=3
ist nicht erreichbarer Code, aber wenn ich Code wie @ ha
public static void main(String args[]){
int x = 0;
if (false) { x=3; }
for( int i = 0; i< 0; i++) x = 3;
}
then es kompiliert korrekt, obwohl der Code inif statement
undfor loop
ist unerreichbar. Warum wird diese Redundanz von der Java-Workflow-Logik nicht erkannt? Irgendein Verwendungszweck?