开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜