Convert Object into primitive int
How to Convert an Object(not String),like TreeNode.item, into primitive开发者_运维问答 like int.
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();
}
hashCode()
might be what you want. Then again, it might not.
精彩评论