org.qi4j.api.common
Annotation Type UseDefaults


@Retention(value=RUNTIME)
@Target(value=METHOD)
@Documented
public @interface UseDefaults

Annotation to denote that the initial value of a Property will be the default value for the type if none is specified during construction.

These are the default values used for various types:

 Byte: 0
 Short: 0
 Character: 0
 Integer: 0
 Long: 0L
 Double: 0.0d
 Float: 0.0f
 Boolean: false
 String: ""
 List: empty java.util.ArrayList
 Set: empty java.util.HashSet
 Collection: empty java.util.ArrayList
 enum: first declared value
 

If this annotation is not used, the property will be set to null, and unless @Optional is declared is not allowed.

It is also possible to change the default values for Composites during the assembly. This is done by calling the ModuleAssembly.forMixin(Class) method.

Example; Let's assume that we have the following mixin type;

 public interface SomeType
 {
     @UseDefaults
     Property someValue();
 }
 
And that we want to have someValue() to be initialized to "<unknown>" instead of the empty string. Then we need to declare the default for that with the following in the assembler.
 public void assemble( ModuleAssembly module )
 {
     module.forMixin( SomeType.class ).declareDefaults().someValue().set( "<unknown>" );
 }
 }