When I try to put final in method parameter eclipse doesn't help. Any idea how to get this to work?
-
3`inal`? sometimes typing is faster than auto completion. – irreputable Sep 19 '10 at 00:46
4 Answers
This probably will be as close as you can get to it. It would be a lot of work to do this for every keyword, but since there is only so many of them it's possible. You could probably take it a step further and just write a template for your methods.
Preferences > Java > Editor > Templates
New > Name (alias)
Pattern: "final "

- 842
- 5
- 14
I don't think this is possible.
The closest thing to this is to set a "save action" which will automatically add final modifiers to method parameters when you save the file.
Preferences > Java > Editor > Save Actions

- 266,786
- 75
- 396
- 414
Assuming that you are complaining about the Eclipse Java editor's completion behavior, I don't think there's anything you can do about it.
If it really worries you, create a bug report on the relevant Eclipse component. Better still, create and submit a patch that fixes the problem.
EDIT
I had a trawl through the Eclipse JDT open bugs/issues, and there are various issues related to final
in various contexts, though not specifically this one (as far as I can see). It is also worth noting that there are a LOT of open JDT issues ... so an issue with a viable patch is much more likely to receive attention.

- 698,415
- 94
- 811
- 1,216
-
It should worry everyone, shdn't it? But the answer fahd is pretty cool! – fastcodejava Sep 19 '10 at 21:38
-
1@fastcodejava - *"It should worry everyone, shdn't it?"* - Why? This is clearly little more than a minor inconvenience. *"But the answer fahd is pretty cool!"* - That depends if you like the idea of the editor rewriting your code without giving you a chance to see what it has just done. I personally dislike that kind of thing. – Stephen C Sep 19 '10 at 21:57
-
@javaguy - that's your opinion. In my opinion (and I guess the JDT developers) it is a minor issue. If you really want/need this functionality, develop a patch and submit it. – Stephen C Sep 21 '10 at 22:27
Java makes a copy of the parameters, the final parameter in this case doesn't do anything, it doesn't help you access it through an inner/anonymous class. Is there a reason you want it?

- 805
- 1
- 8
- 17
-
It keeps you from accidentally re-assigning it. But in that case, I would recommend just turning on the relevant warning instead. – Tyler Sep 19 '10 at 00:50