Final in method parameter in eclipse

你离开我真会死。 提交于 2019-12-08 03:31:12

问题


When I try to put final in method parameter eclipse doesn't help. Any idea how to get this to work?


回答1:


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



回答2:


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.

  1. Preferences > Java > Editor > Templates

  2. New > Name (alias)

  3. Pattern: "final "




回答3:


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.




回答4:


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?



来源:https://stackoverflow.com/questions/3743973/final-in-method-parameter-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!