rspec/rules/S1213/rule.adoc

35 lines
762 B
Plaintext
Raw Normal View History

2020-06-30 12:47:33 +02:00
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:
2021-02-02 15:02:10 +01:00
2021-01-29 15:53:23 +01:00
* Class variables
* Instance variables
2020-06-30 12:47:33 +02:00
* Constructors
* Methods
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:47:33 +02:00
----
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
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:47:33 +02:00
----
public class Foo{
public static final int OPEN = 4;
private int field = 0;
public Foo() {...}
public boolean isTrue() {...}
}
----