Tag Archives: UserInfo()’ in ‘com.example.gmall.cart.pojo.UserInfo’ cannot be applied to ‘(long

[Solved] UserInfo()’ in ‘com.example.gmall.cart.pojo.UserInfo’ cannot be applied to ‘(long, java.lang.String)’

Create a new POJO class

@Data
public class UserInfo {
    private Long userId;
    private String userKey;
}

Use the data annotation in lombook, but make an error when using it

UserInfo()’ in ‘com.example.gmall.cart.pojo.UserInfo’ cannot be applied to ‘(long, java.lang.String)’

Reason: POJO class only uses Data annotation and lacks construction method,

Solution: use annotation @AllArgsConstructor @NoArgsConstructor  or construct directly

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserInfo {
    private Long userId;
    private String userKey;
}