父类
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ParentClass {public String name;
}
子类
@AllArgsConstructor
@NoArgsConstructor
@Data
@SuperBuilder
public class ChildClass<T> extends ParentClass {private T value;
}
提示错误
'builder()' in 'com.zl.test_pro.builder.ChildClass' clashes with 'builder()' in 'com.zl.test_pro.builder.ParentClass'; both methods have same erasure, yet neither hides the other
即出现了类型擦除
解决
子类自定义builder方法
@AllArgsConstructor
@NoArgsConstructor
@Data
@SuperBuilder(builderMethodName = "childBuilder")
public class ChildClass<T> extends ParentClass {public T value;
}
测试
public class BuilderTest {public static void main(String[] args) {ChildClass<String> build = ChildClass.<String>childBuilder().name("zzz").value("child").build();}
}