0

What is the difference between using static public boolean and public static boolean for methods?

I just tried both and both seem to compile fine and have the same effect unless I am doing it wrong. Which one is better and why?

4

2 回答 2

6

There's absolutely no difference, but putting public first is slightly preferred in terms of conventions. From section 8.4.3 of the Java Language Specification:

MethodModifier: one of

Annotation public protected private abstract
static final synchronized native strictfp

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

于 2013-03-30T17:04:12.747 回答
0

I just tried both and both seem to compile fine and have the same effect unless I am doing it wrong. Which one is better and why?

They are pretty same. No difference only first case is less readable. I think second case is more human-readable and you should program for humans so choose option that is more readable. Also by conventions you should use first.

This is similar if you ask for null != obj or obj != null both are same but first case is sometimes used but is much less readable and for me it's annoying.

public static boolean is more readable than static public boolean

于 2013-03-30T17:04:52.853 回答