Why cannot cast Integer to String in java?

Why this is not possible: Because String and Integer are not in the same Object hierarchy. The casting which you are trying, works only if they are in the same hierarchy, e.g. In this case, (A) objB or (Object) objB or (Object) objA will work. Hence as others have mentioned already, to convert an integer to string use: String.valueOf(integer), or Integer.toString(integer) for primitive, … Read more

warning: return makes pointer from integer without a cast but returns integer as desired

It’s not obvious what you’re trying to accomplish here, but I’ll assume you’re trying to do some pointer arithmetic with x, and would like x to be an integer for this arithmetic but a void pointer on return. Without getting into why this does or doesn’t make sense, you can eliminate the warning by explicitly … Read more