Quick question:

Is the proper syntax:

public abstract void myMethod();

OR

abstract public void myMethod();

... The difference being the order of the keywords public and abstract.

Both compile without warnings, but which is the proper syntax?

有帮助吗?

解决方案

According to JLS section 8.1.1

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

If two or more 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.

其他提示

Either is "proper". The difference is a matter of style. I prefer the first.

Both are syntactically correct but

public abstract void myMethod();

is more common. You usually declare the visibility first.

Most common practice is public abstract. I can't actually recall any example or book or any code I've worked with that does the opposite.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top