#primitive array nullability

1 messages · Page 1 of 1 (latest)

unborn osprey
#

So its possible to initialize an array of primitives null, right?
so this is allowed: int[][] test = null
but why do I get "Primitive type members cannot be annotated "
when using jetbrains Nullable annotation on it?

iron tulipBOT
#

<@&987246399047479336> please have a look, thanks.

iron tulipBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

unborn osprey
#

it tells me to move the @Nullable

#

so its like this:

private int[] @Nullable [] test = null;
#

this doesnt seem right

marble turtle
#

Doesn't this work?

#
@Nullable
int[] test = null;
unborn osprey
#

same warning

marble turtle
#

Can I see the warning?

#

Nvm it's in OP

unborn osprey
queen rover
#

I assume it applies to the leftmost type

marble turtle
#

Okay I think I understand it

queen rover
#

which is int

marble turtle
#

It's because you cannot annote a primitive as it's not an object

unborn osprey
#

ik, but I have an array of primitvies

#

and I think its allowed to set this as null

marble turtle
#

A primitive array still won't tick the box

#

As it's not an object

queen rover
#

it is

#

all arrays are reference types

marble turtle
#

oh really

queen rover
#

yes

marble turtle
#

So it's trying to apply the annotation to int[] because...?

queen rover
#

it's tryng to apply the annotation to int

unborn osprey
#

which is obv not allowed

marble turtle
#

Wait no, I'm not fully wrong

queen rover
#

meaning that you want to prevent storing nulls inside the array

marble turtle
#

It doesn't extend object

queen rover
#

for Integer[] that would be fine

marble turtle
#

But its own special type

#

Yeah ^

queen rover
#

but this doesn't prevent the array itself from pointing at null

#

regardless of whether it's primitive or not

marble turtle
#

He's not preventing, it's @Nullable

#

Anyways, squid, no prims!

unborn osprey
#

I think you dont really understand what I want

#

I want to set the array itself null not the elements inside

#

which would be fine for arrays even with primitives

queen rover
#

use kotlin pepekek

unborn osprey
#

💀

marble turtle
#

Integer[] should work though?

queen rover
#

var array: IntArray?

unborn osprey
queen rover
marble turtle
#

You won't get the error with the annotation?

#

Hmm

queen rover
#

once again

unborn osprey
#

as this:

private @Nullable int[][] itemFrameEntityIds = null;

thinks I want to apply the annotation to the int

queen rover
#

you're marking the individual elements as nullable

unborn osprey
#

but this:

private int[] @Nullable [] itemFrameEntityIds = null;

is way to ugly

marble turtle
#

Can you find a source?

queen rover
#

evidently it is, as indicated by the error that he's getting

#

"cannot annotate primitives"

marble turtle
#

@unborn osprey can you try with Integer[]

#

I really think that would get rid of the err

unborn osprey
#

that would remove the warning, but still annotate the elements inside the array instead the array itself

queen rover
#

it will, but would it give the desired outcome?

marble turtle
#

I'm gonna read docs brb

unborn osprey
#

I might just make a new class anyways, that would remove the warning aswell

marble turtle
#

First thing that popped up on Google lol

#

But I might be misunderstanding value parameter as being the contents

unborn osprey
#

I have no idea about kotlin

#

bruh this is actually a possible way of using @Nullable

private @Nullable ItemFrame @Nullable [] @Nullable[] itemFrames;

💀

#

thanks anyways