Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would be the right way to declare qualifiers in java [duplicate]

Tags:

java

Possible Duplicate:
Java modifiers syntax and format

Is it private static final or private final static. I do understand that both of them work, but would like to know the order in which the spec declares it.

like image 752
Jason Avatar asked Sep 13 '11 07:09

Jason


People also ask

What are qualifiers in Java?

A qualifier is an annotation that you apply to a bean. A qualifier type is a Java annotation defined as @Target({METHOD, FIELD, PARAMETER, TYPE}) and @Retention(RUNTIME). For example, you could declare an @Informal qualifier type and apply it to another class that extends the Greeting class.

How do you use @qualifier to identify the bean that should be consumed?

The @Qualifier("student") uniquely identifies this bean with the "student" string. We have another bean called Manager . This bean is also identified with the @Qualifier("manager") annotation. The CommandLineRunner interface indicates that a bean should run when it is contained within a SpringApplication .


2 Answers

The order of access modifiers doesn't matter. They just have to be present.

For method modifiers, the Java language spec notes, that it is it is customary, though not required, that they appear in the order consistent with that shown above in the production for MethodModifier., which is:

(Annotation) public protected private abstract static final synchronized native strictfp

Addition

recommended order for field modifiers (as of JLS 8.3.1):

(Annotation) public protected private static final transient volatile

recommended order for class modifiers (as of JLS 8.1.1):

(Annotation) public protected private abstract static final strictfp

(Annotation) is not a modifier, it's a placeholder for any annotation. Annotations should be put before any other modifier.

like image 189
Andreas Dolk Avatar answered Oct 01 '22 09:10

Andreas Dolk


There is no difference, but one of style.

I prefer private static final

like image 20
Bohemian Avatar answered Oct 01 '22 08:10

Bohemian