Annotation Type ImmutableDefaults


  • @Retention(SOURCE)
    @Target(METHOD)
    public @interface ImmutableDefaults
    Annotation defining which method is to be used to apply the default property values when code generating immutable beans.

    Each non-collection property in an immutable bean normally has to be initialized before use. This annotation allows default values to be set when creating the builder. Note that the defaults apply to the builder, not to the constructor of the bean.

    The method must be a private static void instance method that takes a single argument of the type 'Builder'. Private is necessary as it is called from the builder constructor. For example:

       @ImmutableDefaults
       private static void applyDefaults(Builder builder) {
         builder.group(Group.STANDARD);  // default the group property to 'STANDARD'
       }