搞过java开发的一定遇到过NullPointerException。这是个让人很头疼的问题。JetBrains 开发了一个注解库,通过在 IDE 里面提示开发者处理那些可能为 null 的值来解决这个问题,这个注解库就是JetBrains Annotations。
首先安装插件
https://plugins.jetbrains.com/plugin/22606-microservices-annotator-annotations-extension
然后项目里引入依赖
<dependency>
<groupId>org.jetbrainsgroupId>
<artifactId>annotationsartifactId>
<version>24.0.0version>
dependency>
编写会触发NPE的代码,测试一下这个功能
@Test
public void call() {
String name;
test(name);
}
@NotNull
private String test(@NotNull String name) {
System.out.println(name);
String value;
return value;
}
代码写完时,test(name)这一行即飘红, test方法的返回值也飘红了。编译并运行call方法,无法编译通过。

好工具 ~