public class MainActivity extends AppCompatActivity {
TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = findViewById(R.id.text_view);
String a = "a";
String b = "b";
test(a);
test(b);
}
private void test(String string){
final String localStringFinal = string;
mTextView.setText(localStringFinal);
}
}
The final attached to the local variable (localStringFinal in the example) in the method is You can set the value if the caller is different.
In the example test(a); test(b); A and b are set in. Since the caller is different, b can be set. (Even in final, if the caller is different, the value can be set only once)
Recommended Posts