The authors od Qi4j have noticed that a large number of software bugs are related to the null argument. By disallowing it by default, and required the developer to indicate that optionality is handled explicitly in the code, Qi4j applications becomes inherently more robust, catching null problems early.
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to denote that a method parameter
* is optional, i.e. it can be null. Default
* is that method parameters have to be non-null.
*/
@Retention( RetentionPolicy.RUNTIME )
@Target( { ElementType.PARAMETER, ElementType.METHOD } )
@Documented
public @interface Optional
{
}
SomeType some = ...;
some.first( null ); // Will succeed.
some.second( null ); // Exception will be thrown.