首页 > 解决方案 > 覆盖方法会导致 AndroidStudio 中出现冗余、重复的注解

问题描述

在最近的更新之后,AndroidStudio 会在覆盖方法(通过使用代码 > 生成 > 覆盖方法)时放置这些冗余的重复注释,例如:

@Nullable
@org.jetbrains.annotations.Nullable
@Override
public View onCreateView(@NonNull @org.jetbrains.annotations.NotNull LayoutInflater inflater,
                         @Nullable @org.jetbrains.annotations.Nullable ViewGroup container,
                         @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
    return super.onCreateView(inflater, container, savedInstanceState);
}

我不需要这些@org.jetbrains.annotations.Nullable and @org.jetbrains.annotations.NotNull。只有 with@Nullable或 with@NotNull就足够了。每次重写一个方法,都必须手动删除这样的注解,很痛苦。

以前 AndroidStudio 的行为(理想):

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
                         @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    return super.onCreateView(inflater, container, savedInstanceState);
}

有什么办法可以避免最近 AndroidStudio 的这种行为?

标签: javaandroidandroid-studiointellij-ideajetbrains-ide

解决方案


您可以通过以下方式禁用它们:

首选项/设置>>编辑器>>检查>> Java >>可能的错误>>可空性问题>>取消选中你不想要的

可空性


推荐阅读