Reputation: 49
How to Convert an Object(not String),like TreeNode.item, into primitive like int.
Upvotes: 0
Views: 15799
Reputation: 114767
In response to your last comment: just double-check, that the object is really of type Integer, then use auto-boxing (I assume that your compiler level is 1.5+):
Object o = getTheValue();
int result = 0; // we have to initialize it here!
if (o instanceof Integer) {
result = (Integer) o;
} else {
throw new WTFThisShouldHaveBeenIntegerException();
}
Upvotes: 6
Reputation: 116674
hashCode()
might be what you want. Then again, it might not.
Upvotes: 0