lerad
lerad

Reputation: 225

Create automatically only getters in Eclipse

In Eclipse is it possible to create automatically Getters and Setters for a field. But I have a lot of private fields for which only getters should exist. Is somewhere in Eclipse a "create Getters" Function which does not create setters too?

Well, it is not so much work to write getters, but doing it automatically would be nice :)

Thank you, lerad

Upvotes: 9

Views: 3065

Answers (3)

fastcodejava
fastcodejava

Reputation: 41087

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: http://fast-code.sourceforge.net/getter-setter.jpg
(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.

Upvotes: 1

KrishPrabakar
KrishPrabakar

Reputation: 2842

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)

Upvotes: 0

Bozho
Bozho

Reputation: 597124

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

Upvotes: 12

Related Questions