1

Say I have a class like this:

class Person {

    private String name;
    private int age;

}

I'm lazy, so I let IntelliJ auto-generate the getters for these fields. This is the result:

class Person {

    private String name;
    private int age;

    public String getName() {
        return name;
    }
    //  <-- I don't want this empty line here
    public int getAge() {
        return age;
    }

}

Is there any way to disable the empty lines between the getters (and setters)? I can manually delete them, but if there are a lot of fields it becomes a nuisance.

Gooz
  • 1,106
  • 2
  • 9
  • 20
  • 1
    Why do you actually care? Intellij will fold the code into a single line when you are viewing it, and won't show the line between the folded getters. Whether there is actually a blank line there or not doesn't seem worth troubling yourself over. – Andy Turner Mar 11 '17 at 16:24
  • @AndyTurner When a class has a lot of fields, you also have a lot of getters and setters. When there's an empty line between each of them, they take up double the space. And I just like it that way :) – Gooz Mar 11 '17 at 16:27
  • 1 extra line on top of the 3 you've got is just 33% more. But again: enable code folding: it then takes 66% *less*. – Andy Turner Mar 11 '17 at 16:29
  • @AndyTurner, you said it yourself: Intellij will fold the code into a single line when you are viewing it. That's one line + an empty line. That one empty line is doubling the space it's using. – Gooz Mar 11 '17 at 16:31
  • I think you only want this because get- and set-methods seem pointless. If your method bodies were more substantial, you might appreciate those blank lines more. In an object-oriented design, they should not be just simple returns and assignments; such a design employs defensive copying (which I admit is not going to be used for primitives and Strings like the fields in your example), and validation to guarantee the internal integrity of the object (for example, guaranteeing a field is never null). See also http://stackoverflow.com/questions/1568091/why-use-getters-and-setters . – VGR Mar 11 '17 at 17:16

0 Answers0