what is the values() that I have seen in various CDI qualifiers in java? -
good day.
i have seen various references values() inside @qualifier definitions. understand @qualifier tagging system, yet define them interface.
an interface can allow enums, don't understand word 'values()' i've seen in 2 unrelated examples i've listed below.
could please explain me word values() means?
@qualifier @retention(runtime) @target({field, type, method}) public @interface numberofdigits { digits value(); } public enum digits { two, eight, ten, thirteen }
package com.byteslounge.bean; import static java.lang.annotation.elementtype.field; import static java.lang.annotation.elementtype.type; import static java.lang.annotation.elementtype.method; import static java.lang.annotation.retentionpolicy.runtime; import java.lang.annotation.retention; import java.lang.annotation.target; import javax.inject.qualifier; @qualifier @retention(runtime) @target({field, type, method}) public @interface messagetransport { messagetransporttype value(); }
these not interfaces. these annotations. possible declare static information on annotations , annotate them. code inspects annotations can utilize information.
annotations declared qualifiers let cdi disambiguate between implementations of same type.
consider qualifier foo
:
@qualifier @retention(runtime) @target({field, type, method}) public @interface foo { int value(); }
types annotated foo
:
@foo(1) public class bar implements runnable { //...impl @foo(2) public class baz implements runnable { //...impl
a cdi bean:
public class bean { @inject @foo(1) runnable a; @inject @foo(2) runnable b; //...impl
here, a
resolved instance of bar
while b
resolved instance of baz
.
without qualifier annotation, cdi api wouldn't able tell instance of runnable
inject. values must exact match.
Comments
Post a Comment