Eclipse Members Sort Order vs Oracle Java Code Conventions

In Eclipse, the default is "Member Sort Order" (under "Settings - Java - Appearance - Member Sort Order"):

  • Types
  • Static fields
  • Static Initializers
  • Static methods
  • Fields
  • Initializers
  • Constructors
  • Methods

But Java Conventions Java Code> says the order should be:

  • Class (static) variables
  • Instance variables
  • Constructors
  • Methods

So, Oracle does not distinguish between static and non-static methods in ordering. Because of this, I get a Checkstyle error:

Defining an instance variable in the wrong order.

So I'm wondering if I need to reorder in Eclipse or disable Checkstyle validation. Relying on disabling Checkstyle validation, everyone who joins the project should not change their Eclipse settings, but it seems wrong to ignore the formal conventions.

What are people's views and are there other ways around this?

+5
source share
2 answers

"I am wondering if I should change the order in Eclipse, or turn off Checkstyle checking. Leaning to the side to turn off Checkstyle checking so that everyone who joins the project should not change their Eclipse settings, but it seems a little wrong to ignore the official agreements."

I would suggest modifying Eclipse to fit the rules you want to use. It is advisable to use the Oracles if this is what you want. I usually create Eclipse project files using Maven (so all code formatting is created automatically for new users). I know CXF uses something similar, take a look at their POM for inspiration.

+2
source

Based on Peter Svenssonโ€™s accepted answer, these Checkstyle errors can be resolved using the following sort order of items in Eclipse:

  1. Kinds
  2. Static fields
  3. fields
  4. Static Initializers
  5. Initializers
  6. Constructors
  7. Static Methods
  8. methods
+1
source

All Articles