小编Igo*_*kov的帖子

如何使用Java 8方法对List <List <>>结构中的每个元素应用一些更改

我有一些像 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方法编写此代码?

java foreach list java-8 java-stream

3
推荐指数
1
解决办法
92
查看次数

Lombok @Builder 继承同时为父母和孩子工作

我已经阅读了这篇关于将 lombok@Bulider与继承结合使用的文章https://reinhard.codes/2015/09/16/lomboks-builder-annotation-and-inheritance/ 一切正常。但在我的情况下,我还需要使用 builder for Parent class,而这种解决方法不起作用。

我也尝试添加@BuilderParent 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)

java inheritance builder lombok

1
推荐指数
1
解决办法
2642
查看次数

标签 统计

java ×2

builder ×1

foreach ×1

inheritance ×1

java-8 ×1

java-stream ×1

list ×1

lombok ×1