简体   繁体   English

为什么此方法返回“null”但不返回 null

[英]Why this method returns "null" but not null

I have this method which extracts some info from remittanceInformation object我有这个方法可以从remittanceInformation对象中提取一些信息

private static String combineStrings(RemittanceInformation remittanceInformation) {
        return Optional.ofNullable(remittanceInformation)
                .map(RemittanceInformation::getUstrds)
                .map(l -> l.stream().collect(Collectors.joining(/* CRLF? */)))
                .orElse(null);
    }

Now everything inside remittanceInformation is null and the method in this case should return null but it returns "null" with double quotes, Why this behavior ?现在remittanceInformation所有内容都是null并且在这种情况下的方法应该返回null但它返回带双引号的"null" ,为什么会出现这种行为?

The joining of strings delivers a string, possible "null" (""+null) if there is one term being null.字符串的连接提供一个字符串,如果有一个项为空,则可能是“空”(“”+空)。 That must be the case: a non-null remittanceInformation where getUstrds() gives a collection with a single null.情况一定是这样:一个非空的 remittanceInformation,其中 getUstrds() 给出一个带有单个空值的集合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM