Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dereferencing the integer value of a for loop in java

I just figured out that when I do this in Java:

for(int x = 0; x < 3; x++)
{
    String bla = "bla";
    bla += x.toString();
}

It (Netbeans in this case) will tell me I can not dereference my x integer in such a manner (as I would in C#).

Why is that?

like image 938
Mnescat Avatar asked Aug 22 '11 14:08

Mnescat


1 Answers

Primitive types are not objects in Java, so you need to use other methods to do that, in this case:

Integer.toString(x);
like image 196
Serabe Avatar answered Oct 15 '22 10:10

Serabe