如何使用org.jetbrains.annotations.NotNull
标记的Optional.orElse(null)
orElse
的javadoc明确说明允许null
* @param other the value to be returned, if no value is present.
* May be {@code null}.
但是我的代码在SonarQube中标记了一个“bug”。
return users.findById(userID)
.flatMap(user -> students.findByUser(user))
.map(GetAllStudentsSvc::mapToStudent)
.orElse(null);
从代码上看,它似乎没有被标记。从IDE上看,它也没有被标记。
即使将代码注释为@Nullable
也无济于事。
java.util.Optional
)使用了JetBrains的注释。 - dprSonarLint
的代码检查工具,这可能与他们的代码检查规则有关。 - Deadbeef