java - 为IntelliJ中的所有参数添加@NotNull注释

标签 java intellij-idea annotations copy-paste

对于具有多个参数的方法,例如此构造函数:

    public Chron ( UUID id , UUID trackId , Instant whenCreated , Instant whenLastModified , Instant start , Instant stop , String summary , String notes )

…有没有办法用 @NotNull 标记所有这些参数在 IntelliJ 2019.2 中编辑源代码时添加注释?重复粘贴看起来很愚蠢。

最佳答案

你试过吗@ParametersAreNonnullByDefault如上所述 here .

enter image description here

使用示例位于 package package-info.java 文件中的级别。

@ParametersAreNonnullByDefault
package com.example.acme.backend.data;

import javax.annotation.ParametersAreNonnullByDefault;

要使用此注释,请添加 jsr305 库,它是 Google Code FindBugs 的一部分。项目。查看另一个问题,What is the status of JSR 305?

    <!-- https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305 -->
    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>jsr305</artifactId>
        <version>3.0.2</version>
    </dependency>

关于java - 为IntelliJ中的所有参数添加@NotNull注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57799511/

相关文章:

java - 如何使用 datastore - google appengine 创建用户注册表单?

java - Integer.decode() Java/C#

android-studio - java.lang.AssertionError : Unexpected node Pythonid; nodes=[org. jetbrains.plugins.terminal,org.jetbrains.plugins.javaFX

Javax 验证实现

java - @PreAuthorize注解码合

java - 如何通过英文的 String.format 返回格式化的数字?

java - 使用 'httpClient(postRequest,Handler)'方法获取Http响应状态

intellij-idea - 使用 dart 为 angular2 组件定义提供程序

android-studio - Android Studio 可空性烦人的警告

java - 如何使用带有 iBatis (myBatis) 的注释进行 IN 查询?