How to use getter / setter methods at the bottom of a class definition in intellij

I use the Generate function in the context menu to create getter and setter methods. But it makes no sense to tell Intellij about the placement of the generated methods after the last method in the file, i.e. at the bottom of the class definition. This is possible in Eclipse. Does anyone know how to do this automatically in Intellij?

+6
source share
3 answers

First of all, a small hint. IntelliJ is designed for use without a mouse, so I prefer to use the Alt + Insert keyboard shortcut to generate code.

I donโ€™t know the ability to generally determine the place to insert the generated code. I recommend putting the cursor where you want to paste the generated code, and then generate it.

+11
source
settings > code style > java > arrangement 

allows you to configure automatic formatting options

+2
source

If you want to generate getters and setters through the Create menu, the only way is to place the cursor at the bottom of your class (or wherever you are)

But if your field is not yet used, there is one more option: go to the field for which getter / setter is required, press Alt + Enter (it brings up the dialogue of intentions) and select the option โ€œgenerate getter and setterโ€. Then getter and setter will be generated at the bottom of the class (but not lower than the inner classes, if any).

+1
source

All Articles