0

I have a look at several questions e.g. In Java, should I use “final” for parameters and locals even when I don't have to? on SO and I am a little bit confused after reading the suggestions and answers.

In the project that I ma working on, there are lots of final keywords for the method parameters in methods and interfaced as shown below:

interface:

MenuDTO findMenu(final UUID menuUuid);

implementation:

@Override
public MenuDTO findMenu(final UUID menuUuid) {

}

As far as I know, using final keyword for method parameters as shown above is pointless. So, should I remove the final keywords from the interface methods and their implementations?

  • 1
    Does this answer your question? [Why should I use the keyword "final" on a method parameter in Java?](https://stackoverflow.com/questions/500508/why-should-i-use-the-keyword-final-on-a-method-parameter-in-java) – Unknown Aug 03 '21 at 07:23
  • @Unknown No, actually not Amigo. Because everyone said different thing and that's why I am confused. So, instead of closing questions, could you pls. read the questions when you have time from closing questions. –  Aug 03 '21 at 08:19
  • I did not close the question. But I have marked the question which was similar to the one above. If you want to ensure a variable always points to the same object, mark the variable final. final is used in method parameters to make the references unchangeable after it is passed into the method. – Unknown Aug 03 '21 at 10:38

1 Answers1

0

I also see no meaning in using final in parameters in Java. The final means you cant cant reassign value to variable. This you cant reassign anyway since the value is parameter. It looks for me like this style of writing final is coming from someone who worked with C++ before Java.

Petr F.
  • 161
  • 1
  • 11
  • you right, I meant you cant change value of variable outside method (which should be main focus, not to modify rest of the program), but if you dont want change value of variable insede method, final would work – Petr F. Aug 03 '21 at 07:43