What is the difference between public static and static public?

What is the difference between public staticand static public?

For instance:

static public class MyClass....

Or

public static class MyClass....
+4
source share
5 answers

While there is no difference in functionality (the bytecode will be exactly the same), you want to follow the conventions, visit JLS - 8.3.1. Field Modifiers :

FieldModifiers:
    FieldModifier
    FieldModifiers FieldModifier

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

It will be strange to see static public..

I also recommend that you visit checkstyle .


Edit:

Link from the same page to the section class:

http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.1.1

+3
source

JLS 8.1.1 :

A class declaration may include class modifiers.

ClassModifiers:     ClassModifier     ClassModifiers ClassModifier

ClassModifier:     
     strictfp

() , , , , ClassModifier,

, public static , .

+3

, .

( JLS Java 8 SE) , 8.1.1 Class modifiers:

ClassModifier: , public, protected, private, abstract, static, final, strictfp.

() , , , , ClassModifier.

public static .

+2

, , - public static. , .

+2

Java, 8.1 , , :

ClassDeclaration:
  NormalClassDeclaration
  EnumDeclaration

NormalClassDeclaration:
  {ClassModifier} class Identifier [TypeParameters] [Superclass] [Superinterfaces] ClassBody

ClassModifier:
  Annotation public protected private
  abstract static final strictfp 

{ClassModifier} , ClassModifier (. 2.4 ).

8.1.1 :

This is a compile-time error if the same keyword appears more than once as a modifier for declaring a class.

If two or more (separate) class modifiers appear in a class declaration, then usually, although not required, they are displayed in the order corresponding to that shown above in the work for ClassModifier.

0
source

Source: https://habr.com/ru/post/1570756/


All Articles