Steve Chambers Steve Chambers - 1 month ago 8
Java Question

Eclipse Members Sort Order vs Oracle Java Code Conventions

In Eclipse, the default "Members Sort Order" (in Preferences - Java - Appearance - Members Sort Order) is:


  • Types

  • Static Fields

  • Static Initializers

  • Static Methods

  • Fields

  • Initializers

  • Constructors

  • Methods



But Oracle's Java Code Conventions say the order should be:


  • Class (static) variables

  • Instance variables

  • Constructors

  • Methods



So Oracle don't distinguish between static and non-static methods in the ordering. I'm getting a Checkstyle error because of this:


Instance variable definition in wrong order.


So I'm wondering whether to modify the order in Eclipse or disable the Checkstyle check. Leaning towards disabling the Checkstyle check so everyone who joins the project doesn't have to modify their Eclipse settings but it seems a bit wrong to be ignoring the official conventions.

What are people's views and is there any other way round this?

Answer

"So I'm wondering whether to modify the order in Eclipse or disable the Checkstyle check. Leaning towards disabling the Checkstyle check so everyone who joins the project doesn't have to modify their Eclipse settings but it seems a bit wrong to be ignoring the official conventions."

I would suggest changing Eclipse to conform to the rules that YOU want to use. Preferably using Oracles if that what you want. I usually generate my 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 POMs for inspiration.

Comments