Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: @NonNull for int?

I'm looking for @NonNull equivalent Java annotation for primitive data type. I know primitive data cannot be null, but I wasn't able to find an alternative.

What I'd like to achieve is logically equivalent to:

int mPageNumber;

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

I tried:

int mPageNumber;

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

And I get the following lint warning:

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

What can I put in place of @NonNull and Integer in updatePage method above, so that I can have int as an argument, not Integer?

like image 878
melvynkim Avatar asked Jul 09 '15 23:07

melvynkim


1 Answers

You should change the mPageNumber type to Integer.

As int type can not be null, but Integer can do.

like image 190
Luan Vo Avatar answered Sep 29 '22 10:09

Luan Vo