【发布时间】:2017-09-29 19:47:25
【问题描述】:
public interface A extends C {
String getCh();
String getId();
String getReview();
}
public interface B extends C {
String getCh();
String getId();
String getReview();
}
@Data
@Builder
public class AImpl implements A{
private String ch;
private String id;
private String review;
}
@Data
@Builder
public class BImpl implements B{
private String ch;
private String id;
private String review;
}
so now to use the builders of these I do:
return AImpl.builder()
.ch("ch")
.id("id")
.review("somerview");
For B I do:
return BImpl.builder()
.ch("ch1")
.id("id1")
.review("some new review");
有没有办法可以让这个构建器的一部分变成一个函数?我不喜欢再次重复相同代码的想法。就像我可以在哪里传递 id 频道并在函数中进行审核,我可以在哪里获得对象?
【问题讨论】: