Search code examples
javafinalstatic-variablesclass-variables

Does the order of keywords in variable definition matter?


Is there any difference between the order:

public static final String = "something";

or

public final static String = "something";

?


Solution

  • No, although the Java Language Specification recommends that you use the first ordering:

    FieldModifiers:
      FieldModifier
      FieldModifiers FieldModifier
    
    FieldModifier: one of
      Annotation public protected private
      static final transient volatile
    

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