-3

I've been using the braces on a new line convention for my java project:

public String class()
{
   something;
{

However I have quite a few methods, like getters, that could be written on one line like:

public String getOrderNo(){ return this.orderNo; }

So far I have been correcting this so as everything is in the same format but IntelliJ keeps correcting this. Should I leave this on one line and mix the formats or should I keep changing it so as I am consistent for the whole project?

1 Answers1

2

You do that any way you like.

Multiple lines often makes debugging easier; you may have problems setting a breakpoint on a single line. On the other hand, if you have getters and setters for ten properties, then writing them in twenty lines is much more readable than four lines per setter / getter with an empty line in between for a total of hundred lines. And if you have a typo where property A returns the value b, that will stand out with 20 lines instead of 100.

gnasher729
  • 42,090
  • 4
  • 59
  • 119