A more general solution which should work with 3.0.2+ and 2.4.6+:
@Dependent |
public class Lazy<T> { |
|
private final Handler<T> handler; |
|
@SuppressWarnings("unchecked") |
@Inject |
public Lazy(InjectionPoint injectionPoint, WeldInstance<Object> instance) { |
ParameterizedType parameterizedType = (ParameterizedType) injectionPoint.getType(); |
Type requestedType = parameterizedType.getActualTypeArguments()[0]; |
this.handler = (Handler<T>) instance.select(requestedType, injectionPoint.getQualifiers().toArray(new Annotation[] {})).getHandler(); |
} |
|
public T get() { |
return handler.get(); |
} |
}
|
|