让我们假设我讨厌 null。让我们假设像@Nullable 那样选择退出对我来说还远远不够。假设我希望它选择加入;如果一个对象没有使用@Nullable 显式注释,则不允许使用空值。
例子:
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的源代码?
谢谢!