What would be the correct way to declare qualifiers in java

Possible duplicate:
Java syntax and format

This is private static final or private final static . I understand that both of them work, but would like to know the order in which the specification declares it.

+4
source share
6 answers

The order of access modifiers does not matter. They just have to be present.

For method modifiers, the Java language specification states that this is normal, although it is not required that they be displayed in the order shown above in the MethodModifier method, which:

 (Annotation) public protected private abstract static final synchronized native strictfp 

Adding

Recommended order of field modifiers (from JLS 8.3.1 ):

 (Annotation) public protected private static final transient volatile 

Recommended order of class modifiers (from JLS 8.1.1 ):

 (Annotation) public protected private abstract static final strictfp 

(Annotation) is not a modifier; it is a placeholder for any annotation. Annotations must be placed before any other modifier.

+10
source

There is no difference, but one of the styles.

I prefer private static final

+1
source

In this case, the specification is ยง 8.3 JLS and ยง 8.3.1

<Preview> <i> FieldDeclaration: FieldModifiers opt type VariableDeclarators ; FieldModifiers : <i> FieldModifier FieldModifiers FieldModifier FieldModifier : one of the abstract publicly-protected private static finite transient volatility

As you can see, the order of the field modifiers can be whatever you want. You can even mix annotations anywhere.

+1
source

The order that I saw most is static final , not final static . When this is not part of your code agreement, it is a personal preference. But I would recommend always writing static final , unless you are forced to write it in a different way.

+1
source

I'm not sure if (if?) The spec speaks about this, but one compiles. Therefore, it depends on the preferences of the encoder!

0
source

I cannot find any preference mentioned in any direction in the specification .

0
source

All Articles