Java 키워드 정렬 순서
8.1.1, 8.3.1, 8.4.3 을 읽자
요약
Java Language Specification에서 권장하는 키워드 정렬 순서는 다음과 같다.
Annotations
public
protected
private
abstract
static
final
transient
volatile
synchronized
native
strictfp
checkstyle의 수식어 순서 경고
다음과 같은 메소드를 작성했다고 하자.
// ↓ 여기에 경고
final synchronized protected void hello() {
System.out.println("Hello, World!");
}
그리고 checkstyle을 돌려보면 다음과 같이 protected
가 JLS에서 권장하는 modifier 순서에 맞지 않는다는 경고를 띄운다. (google_checks 사용)
'protected' modifier out of order with the JLS suggestions.
JLS를 찾아보자
JLS는 "Java Language Specification"을 의미한다. 여기에서 봐야 하는 곳은 8.1.1, 8.3.1, 8.4.3 절이다.
A class declaration may include class modifiers.
ClassModifier: (one of) Annotation public protected private abstract static final strictfp
FieldModifier: (one of) Annotation public protected private static final transient volatile
MethodModifier: (one of) Annotation public protected private abstract static final synchronized native strictfp
모두 조합해보면 다음과 같이 정리할 수 있다.
Annotations
, public
, protected
, private
, abstract
, static
, final
, transient
, volatile
, synchronized
, native
, strictfp