org.qi4j.api.common
Annotation Type Optional


@Retention(value=RUNTIME)
@Target(value={PARAMETER,METHOD,FIELD})
@Documented
public @interface Optional

Annotation to denote that something is optional.

Optionality is not the default in Qi4j, and if injections, property values and parameters in methods are not non-null, the Qi4j runtime will throw an ConstraintViolationException, indicating which field/property/parameter in which composite and mixin the problem has been detected.

Example;


 @Optional @Service
 MyService service;   // If no MyService instance is declared and visible to this service injection point
                      // the 'service' field will be null.

 @Service
 YourService other;   // If no YourService instance is declared and visible to this service injection point
                      // the Qi4j runtime will throw a ConstraintViolationException.