我有一些像 List<List<Double>> listOfDoubles我需要将其转换为的结构List<List<Integer>> listOfInteger.我在不使用Java 8的情况下编写代码.它看起来像:
List<List<Integer>> integerList = new ArrayList<>();
for (int i = 0; i < doubleList.size(); i++) {
for (Double doubleValue : doubleList.get(i)) {
integerList.get(i).add(doubleValue.intValue());
}
}
Run Code Online (Sandbox Code Playgroud)
我试图替换第二for,foreach但不能因为i应该是最终的.如何使用Java 8方法编写此代码?
我已经阅读了这篇关于将 lombok@Bulider与继承结合使用的文章https://reinhard.codes/2015/09/16/lomboks-builder-annotation-and-inheritance/
一切正常。但在我的情况下,我还需要使用 builder for Parent class,而这种解决方法不起作用。
我也尝试添加@Builder,Parent class但编译失败,因为Child class尝试覆盖builder()父级的方法。
@AllArgsConstructor
public class Parent {
private final long a;
private final long b;
private final double c;
}
public class Child extends Parent{
private final long aa;
private final long bb;
private final double cc;
@Builder
public Child(long a, long b, long c,
long aa, long bb, long cc)
super(a,b,c);
this.aa = aa;
this.bb = bb;
this.cc =cc; …Run Code Online (Sandbox Code Playgroud)