我正在处理Robolectric的一些代码,具体来说是
IntegerResourceLoader
。当rawValue
为0xFFFF0000之类的值时,以下方法会抛出RuntimeException
:@Override
public Object convertRawValue( String rawValue ) {
try {
return Integer.parseInt( rawValue );
} catch ( NumberFormatException nfe ) {
throw new RuntimeException( rawValue + " is not an integer." );
}
}
我尝试使用Integer.decode(String),但是它抛出了NumberFormatException异常,尽管语法似乎是正确的。
O(1)
操作:parseInt(rawValue.substring(2))
。Java字符串已经为substring
进行了优化(请参阅java.lang.String
中的offset
和count
字段)。 - TWiStErRobInteger.parseInt("98E91E63", 16)
来解析整数。 - BrianInteger.parseInt("98E91E63", 16)
不起作用! - sud007