banner
指数爆炸

指数爆炸

我做了对饭 !
github
bilibili

If a Stream does not have a terminal operation, it will ...

If a Stream does not have a terminal operation, the intermediate operations of this stream will not be executed


This is the code I wrote today, I found that there was no data in the list at the end, so I debugged it, and during debugging I found: the entire peek() operation was not executed, it was skipped directly

List<JSONObject> list = new ArrayList<>();
sbdqas.queryAll(qs).stream()
        .peek(AbstractStandingBookData -> {
            Map<String, String> contentMap = AbstractStandingBookData.toContentMap();
            contentMap.put("totalReceivables", AmountUtil.convertAmountSmallFormat(contentMap.get("totalReceivables")));
            contentMap.put("totalPayable", AmountUtil.convertAmountSmallFormat(contentMap.get("totalPayable")));
            list.add(new JSONObject(contentMap));
        });

Later, I refactored the code, directly returning JSONObject in the map() operation, and the terminal operation toList() worked perfectly!!!

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.