您的位置:程序门 -> java -> 非技术区



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


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


求助!!!谢谢 !!!java中自带的方法如interger.parseint怎么能查看它的实现方法?
发表于:2007-08-28 10:57:38 楼主
java中自带的方法如interger.parseint怎么能查看它的具体实现方法?
发表于:2007-08-28 11:04:121楼 得分:0
/**
          *   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;
}
        }
发表于:2007-08-28 11:08:282楼 得分:0
请问从哪里可以得到这些呢?
发表于:2007-08-28 13:55:163楼 得分:0
在你装好的   %jdk_home%/jdk1.x.0_xx/   目录下有个   src.zip   的压缩包,释放出来(使用“解压到   src/”释放出来)里面就是源代码,可以去看一下。
发表于:2007-08-28 21:26:274楼 得分:0
xie谢谢以上两位
感谢!
发表于:2007-08-28 21:51:245楼 得分:0
用eclipse   点这个方法,然后源代码指向src.zip
发表于:2007-08-28 22:08:026楼 得分:0
使用jbuilder
然后ctrl+enter


快速检索

最新资讯
热门点击