gpt4 book ai didi

java - Eclipse 空分析 : The expression of type int needs unchecked conversion to conform to '@Nonnull Integer'

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:26:03 26 4
gpt4 key购买 nike

在配置Eclipse 4.2.0 执行null分析时(配置使用@javax.annotation.Nonnull等),下面的代码会产生警告

Null type safety: The expression of type int needs unchecked conversion to conform to '@Nonnull Integer'

class C
{
static void foo(int i)
{
bar(i); // Warning
}

static void bar(@javax.annotation.Nonnull Integer i)
{
}
}

我该如何解决这个问题(不使用 @SuppressWarnings("null"))?分析器似乎不知道装箱基元不能为 null

最佳答案

我认为这是 Eclipse 中的错误。我对 IntelliJ 进行了同样的尝试,它在那里按预期工作。

当我传递 Null 时,IntelliJ 正确地告诉我不允许使用 null。

enter image description here

但是,当我使用普通的 i 变量时,没有弹出任何错误,这是非常正确的。 enter image description here

我什至尝试过这个,只是为了实验,所以我不确定你是否坚持使用 Eclipse,否则我建议使用免费的 Community version的 IntelliJ,或 Ultimate edition .

enter image description here

关于java - Eclipse 空分析 : The expression of type int needs unchecked conversion to conform to '@Nonnull Integer' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16241983/

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