publicstaticintparseInt(String s, int radix) throws NumberFormatException { /* * WARNING: This method may be invoked early during VM initialization * before IntegerCache is initialized. Care must be taken to not use * the valueOf method. */
if (s == null) { thrownew NumberFormatException("null"); }
if (radix < Character.MIN_RADIX) { thrownew NumberFormatException("radix " + radix + " less than Character.MIN_RADIX"); }
if (radix > Character.MAX_RADIX) { thrownew NumberFormatException("radix " + radix + " greater than Character.MAX_RADIX"); } int result = 0; boolean negative = false; int i = 0, len = s.length(); int limit = -Integer.MAX_VALUE; int multmin; int digit;
if (len > 0) { char firstChar = s.charAt(0); if (firstChar < '0') { // Possible leading "+" or "-" if (firstChar == '-') { negative = true; limit = Integer.MIN_VALUE; } elseif (firstChar != '+') throw NumberFormatException.forInputString(s);
if (len == 1) // Cannot have lone "+" or "-" throw NumberFormatException.forInputString(s); i++; } ...... ...... ...... } else { throw NumberFormatException.forInputString(s); } return negative ? result : -result; }