Annotation Interface StaticFactory


@Target(CONSTRUCTOR) @Retention(SOURCE) public @interface StaticFactory
Generate a static factory method for the annotated constructor.

Note private constructors will be ignored.

This annotation takes precedence over @StaticFactories and it can be applied to any non-private constructor.

Example

 public final class FactoryFoo
 {
     public FactoryFoo(@Nonnull final String s)
     {
         this(s, 0);
     }

     @StaticFactory("Foo")
     public FactoryFoo(@Nonnull final String s, int i)
     {
     }
 }
 

generates


 public final class Foo {
     private Foo() {
         // no-instances constructor
     }

     public static FactoryFoo factoryFoo(@Nonnull final String s, int i) {
         return new FactoryFoo(s,i);
     }
 }
 
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The name of the class containing the static factory methods.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The name of the factory method.
    The name of the package where to put the class containing the static factory methods.
  • Element Details

    • value

      String value
      The name of the class containing the static factory methods.
    • packageName

      String packageName
      The name of the package where to put the class containing the static factory methods.

      By default, the class will be created in the same package as the annotated class.

      Default:
      ""
    • methodName

      String methodName
      The name of the factory method. By default, it's a lower case version of the annotated class' name.

      Setting this may be necessary when the lower case version of a class name results in a reserved keyword.

      Default:
      ""