1

nullが嫌いだったとしましょう。@Nullable のように、オプトアウトしても十分ではないことにしましょう。オプトインしたいとしましょう。オブジェクトに明示的に @Nullable アノテーションが付けられていない場合、null は許可されません。

例:

MyClass derp = null;           // Compiler error
@Nullable MyClass derp = null; // Fine
@Nullable Integer x = 4;       // Fine
@Nullable Integer x = null;    // Fine
Integer x = 4;                 // Fine
Integer x = null;              // Compiler error

もう一つの例:

public static void myFunction(@Nullable Integer x) {
    Integer y = x;   // Compiler error, because we know x might
                     // be null, and that's not allowed. In other
                     // words: Integer != @Nullable Integer
}

これについてどうすればいいですか?ある種の javac プラグインを作成しますか? おそらくプリコンパイラパス?たぶん、これを行うフレームワークがそこにありますか?それとも、javac のソース コードを変更できますか?

ありがとう!

4

1 に答える 1