scala/scala3

Consider nullable annotations in explicit nulls

Open

#21,629 建立於 2024年9月23日

在 GitHub 查看
 (9 留言) (3 反應) (1 負責人)Scala (1,159 fork)batch import
area:nullabilitycompat:javagood first issueitype:enhancementitype:question

倉庫指標

Star
 (6,247 star)
PR 合併指標
 (平均合併 18天 14小時) (30 天內合併 133 個 PR)

描述

The @NotNull and @NonNullable type annotations are currently used by explicit nulls to not nullify (or add flexible type to) a reference type from Java signatures.

In addition to these annotations, I suggest we also consider the @Nullable annotation. It indicates a value can indeed be null. In this case, we will always nullify the type (adding | Null), instead of adding a flexible type.

// in Java
@Nullable String f(String s)

// in Scala with explicit nulls currently
def f(s: (String)?): (String)?

// in Scala with explicit nulls considering the annotation
def f(s: (String)?): String | Null

A list of @Nullable annotations we may want to consider:

javax.annotation.Nullable
org.jetbrains.annotations.Nullable
org.jspecify.annotations.Nullable
...

貢獻者指南