Annotation Type OptionsByType.Default


  • @Documented
    @Retention(RUNTIME)
    @Target({CONSTRUCTOR,FIELD,METHOD})
    public static @interface OptionsByType.Default
    Defines how an OptionsByType collection may automatically determine a suitable default value for a specific class of option at runtime when the said option does not exist in an OptionsByType collection.

    For example, the OptionsByType.Default annotation can be used to specify that a public static no-args method can be used to determine a default value.

    
     public class Color {
         ...
         @Options.Default
         public static Color getDefault() {
             ...
         }
         ...
     }
     

    Similarly, the OptionsByType.Default annotation can be used to specify a public static field to use for determining a default value.

    
     public class Color {
         ...
         @Options.Default
         public static Color BLUE = ...;
         ...
     }
     

    Alternatively, the OptionsByType.Default annotation can be used to specify that the public no-args constructor for a public class may be used for constructing a default value.

    
     public class Color {
         ...
         @Options.Default
         public Color() {
             ...
         }
         ...
     }
     

    Lastly when used with an enum, the OptionsByType.Default annotation can be used to specify the default enum constant.

    
     public enum Color {
         RED,
    
         GREEN,
    
         @Options.Default
         BLUE;   // blue is the default color
     }
     
    See Also:
    OptionsByType.get(Class)