[英]Convert Object into primitive int
如何将Object(不是String)(例如TreeNode.item)转换为基本类型(例如int)。
回应您的最后一条评论:只需仔细检查一下,该对象确实是Integer类型,然后使用自动装箱(我假设您的编译器级别为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()
可能就是您想要的。 再说一次,可能不会。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.