It is a very simple question, but I think it is a little bit controversial.
When I code Java classes I use the following order.
class Foo {
// static fields
// instance fields
// constructors
// methods (non-static and static methods are mixed but sorted based on their functionalities)
}
I read an article that says:
(From http://code.google.com/webtoolkit/makinggwtbetter.html#codestyle)
Java types should have the following member order:
Nested Types (mixing inner and static classes is okay)
Static Fields
Static Initializers
Static Methods
Instance Fields
Instance Initializers
Constructors
Instance Methods
If I follow the article, the order above should be
class Foo {
// static fields
// static methods
// instance fields
// constructors
// instance methods
}
In the case of the latter, I feel uncomfortable having some methods before constructors. Which one is the more widely-used convention?