i need convert integer value stored inside java object, best way detect kind of value object contains?
for example, when double stored in object this:
double myval = 0.0; object myobj = myval; if (myobj instanceof double) {double dd = (double) myobj; converted = dd.intvalue();}
i dont know if efficient, or best way. since object can contain type of value (double, integer, int, float) best way detect primitive values?
thanks.
edit: after reading answers, realized object cannot contain primitives, so, question wrong. clarifying this!
all object number types subclasses of number:
if (myobj instanceof number) {converted = ((number)myobj).intvalue();}
Comments
Post a Comment