Error: actual and formal argument lists differ in length

3,749 views
Skip to first unread message

SoMa

unread,
Feb 21, 2017, 12:15:42 PM2/21/17
to Project Lombok
Hi,
When I use the @NoArgsConstructor, @EqualsAndHashCode, @ToString and @Builder annotations together then I get the following exception:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project commons: Compilation failure
[ERROR] /home/.../hello/commons/src/main/java/a/b/domain/MyPojo.java:[23,1] constructor MyPojo in class a.b.domain.MyPojo cannot be applied to given types;
[ERROR] required: no arguments
[ERROR] found: java.lang.Long,java.lang.String,java.lang.String,java.lang.Long,java.lang.Long,java.lang.String,a.b.domain.StatusType,java.time.Instant
[ERROR] reason: actual and formal argument lists differ in length


If I remove @Builder then everything works fine. But I need builder to.


This is my class:

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.time.Instant;

@NoArgsConstructor
@EqualsAndHashCode
@ToString
//@Builder
public class Configuration {

@Getter @Setter private Long id;

@Getter @Setter private String key;

@Getter @Setter private String value;

@Getter @Setter private Long userId;

@Getter @Setter private Long refreshInterval;

@Getter @Setter private String description;

@Getter @Setter private StatusType status = StatusType.ACTIVE;

@Getter @Setter private Instant loaded;
}


Could you please help?

Reinier Zwitserloot

unread,
Feb 27, 2017, 5:03:08 PM2/27/17
to Project Lombok
The rules of @Builder state that there must be a suitable constructor (one for all fields). Normally builder makes one for you, but it doesn't if you either have an explicit constructor, or you supply some @XArgsConstructor.

Separate from that, you can make your code A LOT simpler by just using @Data instead of the cavalcade of @Getter, @Setter, @EqualsAndHashCode, and @Builder here.

Thus:

@Builder @NoArgsConstructor @Data @AllArgsConstructor(access = AccessLevel.PACKAGE)
public class Configuration {
    private Long id;
    // other fields
Reply all
Reply to author
Forward
0 new messages