티스토리 뷰

리팩토링 검출 메시지 

"Reorder the modifiers to comply with the Java Language Specification."

Java class, method 선언 시 표현 순서

 1. Annotations

 2. 접근자 (public/protected/private)

 3. abstract

 4. static

 5. final

 6. transient

 7. volatile

 8. default

 9. synchronized

10. native

11. strictfp


잘못된 예 : 

public synchronized static String replace(

...

}



변경 : 

public static synchronized String replace(

...

}

참고 및 발췌

8.1. Class Declarations

A class declaration specifies a new named reference type.

There are two kinds of class declarations: normal class declarations and enum declarations.

The rules in this section apply to all class declarations, including enum declarations. However, special rules apply to enum declarations with regard to class modifiers, inner classes, and superclasses; these rules are stated in §8.9.

The Identifier in a class declaration specifies the name of the class.

It is a compile-time error if a class has the same simple name as any of its enclosing classes or interfaces.

The scope and shadowing of a class declaration is specified in §6.3 and §6.4.

8.1.1. Class Modifiers

A class declaration may include class modifiers.

ClassModifier:
(one of) 
Annotation public protected private 
abstract static final strictfp

The rules for annotation modifiers on a class declaration are specified in §9.7.4 and §9.7.5.

The access modifier public (§6.6) pertains only to top level classes (§7.6) and member classes (§8.5), not to local classes (§14.3) or anonymous classes (§15.9.5).

The access modifiers protected and private pertain only to member classes within a directly enclosing class declaration (§8.5).

The modifier static pertains only to member classes (§8.5.1), not to top level or local or anonymous classes.

It is a compile-time error if the same keyword appears more than once as a modifier for a class declaration.

If two or more (distinct) class modifiers appear in a class declaration, then it is customary, though not required, that they appear in the order consistent with that shown above in the production for ClassModifier.


출처 : https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.1.1


3.1.3 Class and Interface Declarations

The following table describes the parts of a class or interface declaration, in the order that they should appear. See "Java Source File Example" on page 19 for an example that includes comments.



 


Part of Class/Interface Declaration


Notes


1


Class/interface documentation comment (/**...*/)


See "Documentation Comments" on page 9 for information on what should be in this comment.


2


class orinterfacestatement



3


Class/interface implementation comment (/*...*/), if necessary


This comment should contain any class-wide or interface-wide information that wasn't appropriate for the class/interface documentation comment.


4


Class ( static) variables


First the public class variables, then the protected, then package level (no access modifier), and then the private.


5


Instance variables


First public, then protected, then package level (no access modifier), and then private.


6


Constructors



7


Methods


These methods should be grouped by functionality rather than by scope or accessibility. For example, a private class method can be in between two public instance methods. The goal is to make reading and understanding the code easier.



출처 : https://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141855.html#1852

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함