参数化类的原始使用。 Lombok 与 SuperBuilder

问题描述 投票:0回答:1

当尝试使用mapstruct时,我在警告声纳方面遇到问题

Raw use of parameterized class 'CompanyInformationDto.CompanyInformationDtoBuilder'

Unchecked call to 'company(List<Companies>)' as a member of raw type 'com.project.domain.model.company.CompanyInformationData.CompanyInformationDataBuilder'

我的课程:

@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@SuperBuilder
@Getter
@ToString(callSuper = true)
public class CompanyInformationDto extends CompanyInformationData {
}

@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@SuperBuilder
@Getter
@ToString
public class CompanyInformationData {
    ..
}

映射器:

@AfterMapping
default void afterMapping(@MappingTarget CompanyInformationDto.CompanyInformationDtoBuilder  source) { // Raw use of parameterized class 'CompanyInformationDto.CompanyInformationDtoBuilder' 

   List<Companies> companies = new ArrayList<>();
            ....
   source.company(companies).build(); //Unchecked call to 'company(List<Companies>)' as a member of raw type 'com.project.domain.model.company.CompanyInformationData.CompanyInformationDataBuilder'
}

请帮忙,如何解决这个问题?

java lombok mapstruct
1个回答
0
投票

@SuperBuilder
生成一个带有 2 个类型参数的构建器类(除了您的类已有的任何类型参数之外)。第一个类型参数是构建器将生成的类,第二个类型参数是构建器的类型。

当您将构建器作为参数时,这些类型参数并不那么相关。您可以使用

?
通配符来“忽略”它们。将
source
参数的类型更改为:

CompanyInformationDto.CompanyInformationDtoBuilder<?, ?>

这也是

builder
CompanyInformationDto
静态方法的返回类型。


Lombok 需要这些类型参数,这样就不会发生这样的事情:

Subclass.builder()
    .someSuperclassField(foo) // this returns a builder of the superclass!
    .someSubclassField(bar) // oops, there is no someSubclassField in the superclass builder!
© www.soinside.com 2019 - 2024. All rights reserved.