I want to write to a variable only if there isn’t anything already there. Here is my code so far.
if (inv[0] == null) {
inv[0]=map.getTileId(tileX-1, tileY-1, 0);
}
It gives me this error:
java.lang.Error: Unresolved compilation problem:
The operator == is undefined for the argument type(s) int, null
I’m assuming
invis anint[].There’s no such concept as a value “existing” or not in an array. For example:
has exactly the same contents as:
Now if you used an
Integer[]you could use a null value to indicate “unpopulated”… is that what you want?Arrays are always filled with the default value for the element type to start with – which is
nullin the case of reference types such asInteger.