35 lines
762 B
Plaintext
35 lines
762 B
Plaintext
According to the Java Code Conventions as defined by Oracle, the members of a class or interface declaration should appear in the following order in the source files:
|
|
|
|
|
|
* Class variables
|
|
* Instance variables
|
|
* Constructors
|
|
* Methods
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,text]
|
|
----
|
|
public class Foo{
|
|
private int field = 0;
|
|
public boolean isTrue() {...}
|
|
public Foo() {...} // Noncompliant, constructor defined after methods
|
|
public static final int OPEN = 4; //Noncompliant, variable defined after constructors and methods
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,text]
|
|
----
|
|
public class Foo{
|
|
public static final int OPEN = 4;
|
|
private int field = 0;
|
|
public Foo() {...}
|
|
public boolean isTrue() {...}
|
|
}
|
|
----
|
|
|