gpt4 book ai didi

Java:@NonNull 代表 int?

转载 作者:搜寻专家 更新时间:2023-11-01 03:49:57 28 4
gpt4 key购买 nike

我正在寻找原始数据类型的 @NonNull 等效 Java 注释。我知道原始数据不能为 null,但我找不到替代方法。

我想要实现的在逻辑上等同于:

int mPageNumber;

public void updatePage(@NonNull final Integer nonNull) {
mPageNumber = nonNull.intValue();
}

我试过:

int mPageNumber;

public void updatePage(@NonNull final int nonNull) {
mPageNumber = nonNull;
}

我收到以下 lint 警告:

Primitive type members cannot be annotated. This inspection reports problems related to @Nullable and @NotNull annotations usage configured in Constant conditions & exceptions inspection.

在上面的 updatePage 方法中,我可以用什么来代替 @NonNullInteger,这样我就可以拥有 int 作为参数,而不是 Integer

最佳答案

您应该将 mPageNumber 类型更改为 Integer

因为int类型不能为null,但是Integer可以。

关于Java:@NonNull 代表 int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31330139/

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