Dynamically fire CDI event with qualifier with members

淺唱寂寞╮ 提交于 2019-12-01 04:27:58

There's a slightly cleaner way to do it based on your post:

public class TypeQualifier extends AnnotationLiteral<Type> implements Type{

private TypeEnum type;

public TypeQualifier(TypeEnum t) {
      this.type = t;
}

public TypeEnum value() {
    return type;
}

}

then just fire like this:

dynamicEventFirer.fireEvent(new TypeQualifier(TypeEnum.TYPEA));

You need to declare an abstract TypeQualifier that extends AnnotationLiteral and implements Type

abstract class TypeQualifier extends AnnotationLiteral<Type> implements Type{}

and use it like this

dynamicEventFirer.fireEvent(new TypeQualifier() {
public TypeEnum value() {
    return TypeEnum.TYPEA;
}
});

and later if you want to fire an event with TypeEnum.TYPEB

dynamicEventFirer.fireEvent(new TypeQualifier() {
public TypeEnum value() {
    return TypeEnum.TYPEB;
}
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!