The use of Final keyword inside the method argument puzzles me
public void helloWorld(String str)
{
}
public void helloWorld(Final String str)
{
}
What is the differences between them?
The use of Final keyword inside the method argument puzzles me
public void helloWorld(String str)
{
}
public void helloWorld(Final String str)
{
}
What is the differences between them?
public void helloWorld(final String str)
doesn't allow you to change the value of str
locally inside the method, while without the final keyword, you can change it locally.
public void helloWorld(String str)
{
str = "something"; // OK
}
public void helloWorld(final String str)
{
str = "something"; // ERROR
}
Of course, even helloWorld(String str)
can't change the value of the String
passed to the method, since Java is a pass-by-value language.