String can't be cast to an Integer and Integer can't be cast to a String
-
30-10-2019 - |
Question
The getHttpPort
method returns an Object
type derived from a JSON data query. The value of the Object
could be a blank string or an Integer value. To be on the safe side I thought I could represent it as a String like this:
String port = (String)getHttpPort(param);
But this sometimes generates the error:
Integer cannot be cast to a String.
So I tried this:
String port = ((Integer)getHttpPort(param).toString();
But now I get the reverse error:
String cannot be cast to an Integer.
What's the proper way to represent the returned result of the getHttpPort
method as a String?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow