在javac编译的时候, 添加 type checker 插件。
插件在编译的时候,@NotNull 这个注解,进行代码推断吗?
还是仅仅是一个ide(编译器的提示)
本质上, 插件有能力(借助type checker 注解)分析代码, 增强代码的健壮性码?
https://blogs.oracle.com/java-platform-group/java-8s-new-type-annotations
Other annotations, like @NonNull and @Readonly can be used by analyzers like the Checker Framework, FindBugs, Eclipse, NetBeans, IntelliJ, or a commercial analyzer. Those analyzers can then be run at compile time, through IDE background compilation, Ant/Maven, or continuous integration.
type checkers
https://checkerframework.org/manual/#installation
The Checker Framework lets you run an additional type-checker as a plug-in to the javac compiler.
type checkers 分析当前类中可能发生的异常
举例:
import org.checkerframework.checker.nullness.qual.Nullable;
class YourClassNameHere {
void foo(Object nn, @Nullable Object nbl) {
nn.toString(); // OK
nbl.toString(); // Error
}
}
compile失败, 因为nbl可能是null
@Nullable 告诉compiler 可能为null
@NotNull 告诉compiler 不为null