Increment a Integer's int value?

How do I increment a Integer’s value in Java? I know I can get the value with intValue, and I can set it with new Integer(int i).

playerID.intValue()++;

does not seem to work.

Note: PlayerID is a Integer that has been created with:

Integer playerID = new Integer(1);

You can’t, Integer objects are immutable.

playerID = new Integer(playerID.intValue()+1);

Also, the above will never ever work. You can’t modify a primitive return value and hope it will do something to the original value, because it won’t. :slight_smile:

Yeah, I know. I dunno what I was thinking ^^;

It happens.

I remember having some code in a commercially released game that looked like this:


object = null;
if (object != null)
{
    //this will never happen, doi!
}

yeh ive seen a similar thing while debugging my mates code,


do

Blah = 0;

if Blah != 0
{
       blah = 0;
}

while != (WindowColseRequested)


i was like Dude what is wrong with you

(obviously there was more code in there but eh couldn’t remember it was a while ago, also this was c#)