What I've always been interested in in Java final

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

What I've always been interested in in Java final
[Java] What got caught in encapsulation
What is a class in Java language (3 /?)
Difference between final and Immutable in Java
What is a class in Java language (1 /?)
What is the main method in Java?
What Java programmers find useful in Kotlin
[Java] Use of final in local variable declaration
Dynamically change private static final fields in Java
What is java
Partization in Java
Changes in Java 11
Rock-paper-scissors in Java
What is Java <>?
What is Java
Pi in Java
java final modifier
FizzBuzz in Java
[Java] Difference between static final and final in member variables
What I learned in Java (Part 3) Instruction execution statement
What I learned when building a server in Java
I tried to find out what changed in Java 9