为什么Integer.getInteger不起作用? [英] Why Integer.getInteger does not work?

查看:138
本文介绍了为什么Integer.getInteger不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

game.log.fine("HERE" + bestMove.get("score"));
Integer bestScore = Integer.getInteger(bestMove.get("score"));
game.log.fine("THERE" + bestScore);

作为输出我有:

FINE: HERE50
Dec 9, 2010 11:34:17 AM game.Agent getCloud
FINE: THEREnull
Dec 9, 2010 11:34:17 AM game.Agent getCloud

可能我必须添加bestMove HashMap<字符串,字符串>

Probably I had to add that bestMove is HashMap<String,String>.

问题是 bestMove.get(得分)给出一个字符串值(等于50)。但是如果尝试转换为整数,我得到 null

The problem is that bestMove.get("score") gives a string value (equal to "50"). But if try to transform to integer, I get null.

有人知道这里有什么问题吗? / p>

Does anybody know what is the problem here?

推荐答案

因为 Integer.getInteger 不是您要搜索的内容。来自Javadoc:

Because Integer.getInteger is not what you're searching for. From the Javadoc :


确定具有指定
名称的
系统属性的整数值。第一个参数被视为
系统属性的名称。系统
属性可通过
System.getProperty(java.lang.String)
方法访问。然后将此
属性的字符串值解释为
整数值,并返回表示此值的Integer对象

可以使用
getProperty的定义找到
的详细信息。

Determines the integer value of the system property with the specified name. The first argument is treated as the name of a system property. System properties are accessible through the System.getProperty(java.lang.String) method. The string value of this property is then interpreted as an integer value and an Integer object representing this value is returned. Details of possible numeric formats can be found with the definition of getProperty.

如果$ b没有属性$ b指定的名称,如果指定的名称
为空或null,或者属性
没有正确的数字
格式,则返回null。

If there is no property with the specified name, if the specified name is empty or null, or if the property does not have the correct numeric format, then null is returned.

您想使用 Integer.parseInt

这篇关于为什么Integer.getInteger不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆