Java Reference
In-Depth Information
After these two simple steps, NetBeans generates the code for our qualifier.
package com.ensode.qualifier;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
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({METHOD, FIELD, PARAMETER, TYPE})
public @interface Premium {
}
Qualifiers are standard Java annotations, they typically have retention of runtime
and can target methods, fields, parameters, or types. The only difference between
a qualifier and a standard annotation is that qualifiers are decorated with the @
Qualifier annotation.
Once we have our qualifier in place, we need to use it to decorate the specific
subclass or interface implementation.
package com.ensode.model;
import com.ensode.qualifier.Premium;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
@Named
@RequestScoped
@Premium
public class PremiumCustomer extends Customer {
private Integer discountCode;
public Integer getDiscountCode() {
return discountCode;
}
public void setDiscountCode(Integer discountCode) {
this.discountCode = discountCode;
}
}
 
Search WWH ::




Custom Search