Reputation: 11
int i = 0;
String[] b = new String[]{releaseId, i});
causes an int cannot be converted to java.lang.String
From what I know java does implicit String conversion (in case of non-primitives a call to toString()) ?
So what is wrong here?
Is there something different about Java for Android?!
Upvotes: 0
Views: 12974
Reputation: 53
There are 2 "good" ways to convert an integer to a String. Integer.toString(i)
or String.valueOf(i)
.
It is possible to do something like this String s = "" + i;
but that is considered a bad smell.
Upvotes: 0
Reputation: 2580
Yes,
int cannot be converted to java.lang.String
Java doing implicit String
conversion for Objects, not for primitive types.
You need to use Integer
or String.valueOf(i)
.
Upvotes: 1
Reputation: 157487
From what I know java does implicit String conversion (in case of non-primitives a call to toString()) ? So what is wrong here?
That's true for objects. int is a primitive type not an object.
Use String.valueOf(i)
to retrieve the String representation of i
Upvotes: 8