例如考虑下面的代码
List<Reference> references = context.getReferences()
.stream()
.filter(ref -> ref.getCondition() == SOMETHING_DESIRABLE)
.collect(Collectors.toList());
现在,如果我改变 references
列表中的每个引用,它会反射(reflect)在原始 context.references
中吗?
最佳答案
在 Java 中没有克隆对象的通用方法。
它根本上不可能自动返回不同的实例。
关于java - Java 8 Streams Filter 和 Collect 是否返回对列表中相同对象的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45827962/