Hacker News new | ask | show | jobs
by cloogshicer 1886 days ago
This is not immutability, final only prevents re-assignment, not mutation:

    final ArrayList<String> foo = new ArrayList<>();
    foo.add("Foo"); // Compiles and runs - this is mutation
    foo = new ArrayList<>(); // Compiler error - this is re-assignment
In your example, both Strings are immutable, since Java Strings are always immutable.
1 comments

The variable is immutable.