You can't because of variable scope.
If you define the variable inside an if
statement, than it'll only be visible inside the scope of the if
statement, which includes the statement itself plus child statements.
if(...){
String a = "ok";
// a is visible inside this scope, for instance
if(a.contains("xyz")){
a = "foo";
}
}
You should define the variable outside the scope and then update its value inside the if
statement.
String a = "ok";
if(...){
a = "foo";
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…