Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
It works because a new object is returned. The variable 'x' does not change.
public String replace(char oldChar, char newChar)
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
Warning: a mutable object declared as final will still be mutable. The only thing that
final
locks is the binding between the variable name and the reference of the object in memory, so final "protects the code" only when used on immutable data structures or basic data types:If you try to assign new object or value to the variable with final keyword, the code will not compile.
You should use it, if you specifically do not want any other programmist (or yourself) to change the value, because some of your code depends on it. In example:
final double PI = 3.1415;
// PI = 10.0; this line would not compile
In this kata:
x = "my custom solution"; // would not compile