Java Modifier Keyword Order

Oct
21

After doing some Java development with Sonar, I soon realized that there is a reasonable order that some modifiers should be in. This piqued my interest, so I did some research. This is what I found:

According to the Java Language Specification* the order of modifiers is encouraged be:

@Annotation
[ public | protected | private ]
static
abstract
final
native
synchronized
[ transient | volatile ]
strictfp
[ int | long | byte | class | enum | interface | etc. ]

* http://docs.oracle.com/javase/specs/jls/se7/html/jls-18.html

It is important to note that the order of most modifiers does not matter, but it is good practice to remain consistent throughout your development.

Tags: #Java Author: Seth Westphal
comments powered by Disqus