0

I usually go into 'Source' to generate code automatically such as constructors, get and set methods and more. Is there a faster alternative?

Cyborg 3.0
  • 19
  • 4
  • What do you mean "set methods"? Are you talking about code generation? – John Bollinger Aug 05 '16 at 13:46
  • 1
    Depending on your click/type ratio, it might be faster to type `set` and hit Ctrl+Space for auto-suggestng the setter. Or use [`lombok`](https://projectlombok.org/) – tobias_k Aug 05 '16 at 13:53
  • JPA (such as eclipseLink) generates rhe entity classes for you from the database, For the rest do not use many fields, and try `final` fields, that might often be even `public final`. – Joop Eggen Aug 05 '16 at 13:53
  • How long does it take you to do the method you're doing? We don't have enough information to determine whether you are faster at doing one thing or the other. – TylerH Aug 05 '16 at 14:21

2 Answers2

3

Another approach could be to use a third party library like Lombok. By adding the lombok.jar to your project, you only need to add annotations to your variables. Getters and setters will be created automatically when you compile your code, which makes your code short. You only need something like this:

@Getter @Setter 
public String name;

No code needed for setter/getter methods, they will be generated at run time.

Rosa
  • 642
  • 6
  • 20
Eritrean
  • 15,851
  • 3
  • 22
  • 28
2

If you want a shortcut to generate setters and getters, try:

ALT+SHIFT+S+R

This opens the getter/setter dialog box. You have to press all 4 keys.

Rosa
  • 642
  • 6
  • 20
Eritrean
  • 15,851
  • 3
  • 22
  • 28
  • Wow ! Netbeans as a simpler way `ALT + INSERT` but I will remember this one, using the autocompletion works for one but for multiple generation, this is perfert ! – AxelH Aug 05 '16 at 14:11
  • @AxelH You don't need to remember it, you can change it to whatever you like. – biziclop Aug 05 '16 at 14:13
  • You can press the first three keys separately from the last. `ALT`+`SHIFT`+`S` opens up the Source context menu, and `R` selects out of that menu. – Rosa Aug 05 '16 at 14:31