Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java checkstyle - constructor definition in wrong order

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.

like image 478
Ben Lu Avatar asked Mar 04 '13 04:03

Ben Lu


1 Answers

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.

like image 181
n00begon Avatar answered Oct 27 '22 00:10

n00begon