I want to convert a primitive to a string, and I tried:
myInt.toString();
This fails with the error:
int cannot be derefere
Java autoboxing/unboxing doesn't go to the extent to allow you to dereference a primitive, so your compiler prevents it. Your compiler still knows myInt
as a primitive. There's a paper about this issue at jcp.org.
Autoboxing is mainly useful during assignment or parameter passing -- allowing you to pass a primitive as an object (or vice versa), or assign a primitive to an object (or vice versa).
So unfortunately, you would have to do it like this: (kudos Patrick, I switched to your way)
Integer.toString(myInt);