Programing/JVM(Java, Kotlin)

[Java] Sonarqube: Modifiers should be declared in the correct order

나모찾기 2020. 10. 26. 12:37

기본이지만 가끔 헷갈릴때가 있다. java:S1124

Modifiers should be declared in the correct order

  • Code Smell
  • Minor
  • Available SinceJul 31, 2018
  • SonarQube (Java)
  • Constant/issue: 2min

The Java Language Specification recommends listing modifiers in the following order:

1. Annotations

2. public

3. protected

4. private

5. abstract

6. static

7. final

8. transient

9. volatile

10. synchronized

11. native

12. strictfp

Not following this convention has no technical impact, but will reduce the code's readability because most developers are used to the standard order.

Noncompliant Code Example

static public void main(String[] args) { // Noncompliant }

Compliant Solution

public static void main(String[] args) { // Compliant }