首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java面试 >

!多谢 !java中自带的方法如interger.parseInt如何能查看它的实现方法

2012-04-11 
求助!!!谢谢 !!!java中自带的方法如interger.parseInt怎么能查看它的实现方法?java中自带的方法如interger

求助!!!谢谢 !!!java中自带的方法如interger.parseInt怎么能查看它的实现方法?
java中自带的方法如interger.parseInt怎么能查看它的具体实现方法?

[解决办法]
/**
* Parses the string argument as a signed integer in the radix
* specified by the second argument. The characters in the string
* must all be digits of the specified radix (as determined by
* whether {@link java.lang.Character#digit(char, int)} returns a
* nonnegative value), except that the first character may be an
* ASCII minus sign <code> '- ' </code> ( <code> '&#92;u002D ' </code> ) to
* indicate a negative value. The resulting integer value is returned.
* <p>
* An exception of type <code> NumberFormatException </code> is
* thrown if any of the following situations occurs:
* <ul>
* <li> The first argument is <code> null </code> or is a string of
* length zero.
* <li> The radix is either smaller than
* {@link java.lang.Character#MIN_RADIX} or
* larger than {@link java.lang.Character#MAX_RADIX}.
* <li> Any character of the string is not a digit of the specified
* radix, except that the first character may be a minus sign
* <code> '- ' </code> ( <code> '&#92;u002D ' </code> ) provided that the
* string is longer than length 1.
* <li> The value represented by the string is not a value of type
* <code> int </code> .
* </ul> <p>
* Examples:
* <blockquote> <pre>
* parseInt( "0 ", 10) returns 0
* parseInt( "473 ", 10) returns 473
* parseInt( "-0 ", 10) returns 0
* parseInt( "-FF ", 16) returns -255
* parseInt( "1100110 ", 2) returns 102
* parseInt( "2147483647 ", 10) returns 2147483647
* parseInt( "-2147483648 ", 10) returns -2147483648
* parseInt( "2147483648 ", 10) throws a NumberFormatException
* parseInt( "99 ", 8) throws a NumberFormatException
* parseInt( "Kona ", 10) throws a NumberFormatException
* parseInt( "Kona ", 27) returns 411787
* </pre> </blockquote>
*
* @param s the <code> String </code> containing the integer
* representation to be parsed
* @param radix the radix to be used while parsing <code> s </code> .
* @return the integer represented by the string argument in the
* specified radix.
* @exception NumberFormatException if the <code> String </code>
* does not contain a parsable <code> int </code> .
*/
public static int parseInt(String s, int radix)
throws NumberFormatException
{
if (s == null) {
throw new NumberFormatException( "null ");
}

if (radix < Character.MIN_RADIX) {
throw new NumberFormatException( "radix " + radix +
" less than Character.MIN_RADIX ");
}

if (radix > Character.MAX_RADIX) {
throw new NumberFormatException( "radix " + radix +
" greater than Character.MAX_RADIX ");
}

int result = 0;
boolean negative = false;
int i = 0, max = s.length();
int limit;
int multmin;
int digit;

if (max > 0) {
if (s.charAt(0) == '- ') {


negative = true;
limit = Integer.MIN_VALUE;
i++;
} else {
limit = -Integer.MAX_VALUE;
}
multmin = limit / radix;
if (i < max) {
digit = Character.digit(s.charAt(i++),radix);
if (digit < 0) {
throw NumberFormatException.forInputString(s);
} else {
result = -digit;
}
}
while (i < max) {
// Accumulating negatively avoids surprises near MAX_VALUE
digit = Character.digit(s.charAt(i++),radix);
if (digit < 0) {
throw NumberFormatException.forInputString(s);
}
if (result < multmin) {
throw NumberFormatException.forInputString(s);
}
result *= radix;
if (result < limit + digit) {
throw NumberFormatException.forInputString(s);
}
result -= digit;
}
} else {
throw NumberFormatException.forInputString(s);
}
if (negative) {
if (i > 1) {
return result;
} else {/* Only got "- " */
throw NumberFormatException.forInputString(s);
}
} else {
return -result;
}
}
[解决办法]
在你装好的 %JDK_HOME%/jdk1.x.0_xx/ 目录下有个 src.zip 的压缩包,释放出来(使用“解压到 src/”释放出来)里面就是源代码,可以去看一下。
[解决办法]
用eclipse 点这个方法,然后源代码指向src.zip
[解决办法]
使用JBuilder
然后Ctrl+Enter

热点排行