Package lombok

Annotation Type NoArgsConstructor


@Target(TYPE) @Retention(SOURCE) public @interface NoArgsConstructor
Generates a no-args constructor. Will generate an error message if such a constructor cannot be written due to the existence of final fields.

Complete documentation is found at the project lombok features page for @Constructor.

Even though it is not listed, this annotation also has the onConstructor parameter. See the full documentation for more details.

NB: Fields with constraints such as @NonNull will NOT be checked in a @NoArgsConstructor constructor, of course!

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    Deprecated.
    Don't use this annotation, ever - Read the documentation.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Sets the access level of the constructor.
    boolean
    If true, initializes all final fields to 0 / null / false.
    Any annotations listed here are put on the generated constructor.
    If set, the generated constructor will be private, and an additional static 'constructor' is generated with the same argument list that wraps the real constructor.
  • Element Details

    • staticName

      String staticName
      If set, the generated constructor will be private, and an additional static 'constructor' is generated with the same argument list that wraps the real constructor. Such a static 'constructor' is primarily useful as it infers type arguments.
      Returns:
      Name of static 'constructor' method to generate (blank = generate a normal constructor).
      Default:
      ""
    • onConstructor

      Any annotations listed here are put on the generated constructor. The syntax for this feature depends on JDK version (nothing we can do about that; it's to work around javac bugs).
      up to JDK7:
      @NoArgsConstructor(onConstructor=@__({@AnnotationsGoHere}))
      from JDK8:
      @NoArgsConstructor(onConstructor_={@AnnotationsGohere}) // note the underscore after onConstructor.
      Returns:
      List of annotations to apply to the generated constructor.
      Default:
      {}
    • access

      AccessLevel access
      Sets the access level of the constructor. By default, generated constructors are public.
      Returns:
      The constructor will be generated with this access modifier.
      Default:
      PUBLIC
    • force

      boolean force
      If true, initializes all final fields to 0 / null / false. Otherwise, a compile time error occurs.
      Returns:
      true to force generation of a no-args constructor, picking defaults if necessary to assign required fields.
      Default:
      false