I've searched the API for something that will do this easily and can't find a straight-forward way to do it. If you can get a wrapper class for the primitive then you can call getClass().toString() on it, to tell which type you have. It would be nice if the java.lang.Number class had a getInstance() method for each of the java primitives that would return an Instance of the correct wrapper. such as Double getInstance(double d) Float getInstance(float f) so that at runtime the correct method would be called and you could get the correct instance. If you wanted to, you could write this static class yourself consisting of a static getInstance method for each of the 8 primitives. Should only be ~20 lines of code anyway.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Joined: Sep 29, 2000
Not to bring up an old topic... but that old discussion only gives you the corresponding Class reference for a primitive type. Not the type of the result of a conversion operation dynamically. I'm assuming he's wanting this for testing conversion/casting in Java and perhaps wanting to know what type the following yields : double d = 5.0 float f = 6.0 getInstance(d + f).getClass().toString(); would be a (painful, but workable) way to do this.