A pit annotation using the @Builder of lombok

Development projects being given a say

java.lang.Long,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.Integer,java.lang.Integer,java.util.Date,java.util.Date,java.lang.Integer,java.lang.Integer,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.Integer 

Reason: the different forms and the actual argument list parameter list length, see pointing error message

@Builder

Strange, how builder will complain?

text

See an error message that is less than full-match argument constructor, because the project using a lombok, my comments are as follows

  1. @Data
  2. @NoArgsConstructor
  3. @Builder

We have a default constructor parameters, how could an error? Do builder guess by default, it is the whole argument to the constructor? Try added @AllArgsConstructor, really good. I checked the Internet information

  1.  
    The builder annotation creates a so-called 'builder' aspect to the class that is annotated or the class that contains a member which is annotated with @Builder.
  2.  
    If a member is annotated, it must be either a constructor or a method. If a class is annotated, then a private constructor is generated with all fields as arguments (as if @AllArgsConstructor(AccessLevel.PRIVATE) is present on the class), and it is as if this constructor has been annotated with @Builder instead.
  3.  
     
  4.  
    The effect of @Builder is that an inner class is generated named TBuilder, with a private constructor. Instances of TBuilder are made with the method named builder() which is also generated for you in the class itself (not in the builder class).
  5.  
     
  6.  
    The TBuilder class contains 1 method for each parameter of the annotated constructor / method (each field, when annotating a class), which returns the builder itself. The builder also has a build() method which returns a completed instance of the original type, created by passing all parameters as set via the various other methods in the builder to the constructor or method that was annotated with @Builder. The return type of this method will be the same as the relevant class, unless a method has been annotated, in which case it'll be equal to the return type of that method.

Its implementation is found to have marked this comment to all members of the class variables, so when using @Builder built without explicit assignment to a variable, then the default is null, because this variable at this time is in the Builder
class generated by specific T category is a private constructor to instantiate, full default constructor parameters by calling build () method.

@Builder default implementation is to add @AllArgsConstructor (access = AccessLevel.PACKAGE) in the class

Guess you like

Origin www.cnblogs.com/zhjh256/p/11333045.html