gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 17:20:07 25 4
gpt4 key购买 nike

问题:

@Nullable
private View view;

public doSomethingWithView() {
checkNotNull(view); //<- this throws NPE if parameter is null
view.showWarningAboutIssue(); //<- IDE reports about possible null here
}

有没有办法配置 IDE,使其不在第二行报告可能的 NPE?

更新:我正在使用 Dagger checkNotNull 方法,它与 Guava 方法相同。如果我将导入从 Dagger 更改为 Guava,我的 IDE 会删除警告。

更新#2随着 Android Studio 的最新更新,我无法再复制它了

最佳答案

您需要在view.showWarningAboutIssue()语句之前添加如下注释:

//noinspection ConstantConditions

这也可以通过 GUI 执行:Alt+Enter(或“bubblelight”菜单),然后选择 Assert view!=null,然后选择 Suppress for 语句:

enter image description here

关于android-studio - Android Studio 可空性烦人的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37761520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com