gpt4 book ai didi

java - Optional.orElse(null) 用 org.jetbrains.annotations.NotNull 标记

转载 作者:行者123 更新时间:2023-12-04 13:34:59 27 4
gpt4 key购买 nike

怎么样Optional.orElse(null)标有 org.jetbrains.annotations.NotNullorElse的javadoc明确指出允许空值

     * @param other the value to be returned, if no value is present.
* May be {@code null}.
但是我的代码在 SonarQube 中标记了一个“错误”。
        return users.findById(userID)
.flatMap(user -> students.findByUser(user))
.map(GetAllStudentsSvc::mapToStudent)
.orElse(null);
查看代码它似乎没有被标记。查看 IDE,它似乎也没有被标记
enter image description here
甚至将代码注释为 @Nullable没有帮助。
enter image description here

最佳答案

我认为很明显null在这里完全没问题,所以我建议压制它。这对我有用:@SuppressWarnings("squid:S2637")

关于java - Optional.orElse(null) 用 org.jetbrains.annotations.NotNull 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62732852/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com