Create automatically only getters in Eclipse

天涯浪子 提交于 2019-12-03 12:32:35

On the Generate Setters and Getters screen you have Select getters button on the right - use it.

fastcodejava

What do you mean by automatically? My plugin lets one create fields with Getters or Setters. You might look into this : http://fast-code.sourceforge.net/. It has simple popup as below:


(source: sourceforge.net)

I should mention that eclipse has create Getters/Setters from the source menu. It also puts a marker beside any private member. Then one just needs to press Ctrl-1. Problem with that is it creates both getters or setters.

One more (may be nasty) way of creating only getters is:

  1. Create the member variables with final modifier (such as private final int hoursSpentInSO)
  2. While in editor, and press Alt + Shift + s, r (Press the r key after a slight delay)
  3. You will get only getters for those final fields, press OK
  4. Once getters are generated, remove the final modifier (if required)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!