3 ms·
This is not immutability, final only prevents re-assignment, not mutation: final ArrayList<String> foo = new ArrayList<>(); foo.add("Foo"); // Compiles
by cloogshicer 6y 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.
- imtringued 6y agoThe variable is immutable.