13

I have a class that looks like this:

public final class OrderedSetList<T extends Comparable<? super T>> implements OrderedSet<T> {

    // Constructor definition in wrong order checkstyle error next line
    public OrderedSetList() {      
        // Initializations
    }
}

Can anyone tell me why there is a "Constructor definition in wrong order" error in my constructor?

It's an assignment and we have our own checkstyle configs and any checkstyle error is not allowed.

I appreciated your help.

3
  • 2
    Is the constructor the first method?
    – n00begon
    Commented Mar 4, 2013 at 4:07
  • @Glitch Nope. Is this a problem?
    – Ben Lu
    Commented Mar 4, 2013 at 4:09
  • 1
    I think that checkstyle rule wants the constructor as the first method. Try shifting it up to just below your variables.
    – n00begon
    Commented Mar 4, 2013 at 4:10

1 Answer 1

20

The checkstyle rule is making sure you are following the code conventions for the order of your declarations:

The parts of a class or interface declaration should appear in the following order:
Class (static) variables. First the public class variables, then the protected, then package level (no access modifier), and then the private.
Instance variables. First the public class variables, then the protected, then package level (no access modifier), and then the private.
Constructors
Methods

It wants the constructor to be the first method.

1
  • 1
    You should also quote the checkstyle rules, a few points are not that much to copy.
    – A--C
    Commented Mar 4, 2013 at 4:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.