什么是Lenses ?是可链接的getter 和 setter :
pendingOrders.map(setApprovalConfirmationUpdatedOn(LocalDateTime.now())); |
为我们提供了一种更新复杂的、可能嵌套的、不可变的对象的方法,而无需我们通常必须忍受的任何可怕的样板。
上述代码的样版写法是:
pendingOrders.map(order -> |
借助于Deoplice库,可对下面代码简化:
List<Comment> original = order.getApproval().getComments() |
下面是使用 Deoplice 生成的 API 时完全相同的操作:
addApprovalComment(Comment.of("lgtm!")).apply(order); |
这就是使用现代工具更新不可变数据类的样子。
详细点击标题