@Retention(value=RUNTIME) @Target(value={METHOD,FIELD}) @Documented public @interface UseDefaults
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
org.qi4j.bootstrap.ModuleAssembly#forMixin(Class)
method.
Example; Let's assume that we have the following mixin type;
public interface SomeType
{
@UseDefaults
Property<String> 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>" );
}
}