日期:2014-05-20  浏览次数:20874 次

java的scan是干什么用的?
看string类的时候,无意看见了居然在方法里面抛出nullpointexception,很奇怪,在仔细往下一看,有个scan;看代码:
Java code

    public String toUpperCase(Locale locale) {
    if (locale == null) {
        throw new NullPointerException();
        }

        int     firstLower;

    /* Now check if there are any characters that need to be changed. */
    scan: {
        for (firstLower = 0 ; firstLower < count; ) {
        int c = (int)value[offset+firstLower];
        int srcCount;
        if ((c >= Character.MIN_HIGH_SURROGATE) &&
            (c <= Character.MAX_HIGH_SURROGATE)) {
            c = codePointAt(firstLower);
            srcCount = Character.charCount(c);
        } else {
            srcCount = 1;
        }
        int upperCaseChar = Character.toUpperCaseEx(c);
        if ((upperCaseChar == Character.ERROR) ||
            (c != upperCaseChar)) {
            break scan;
        }
        firstLower += srcCount;
        }
        return this;
    }

        char[]  result       = new char[count]; /* may grow */
    int     resultOffset = 0;  /* result may grow, so i+resultOffset
                    * is the write location in result */

    /* Just copy the first few upperCase characters. */
    System.arraycopy(value, offset, result, 0, firstLower);

    String lang = locale.getLanguage();
    boolean localeDependent =
            (lang == "tr" || lang == "az" || lang == "lt");
        char[] upperCharArray;
        int upperChar;
        int srcChar;
        int srcCount;
        for (int i = firstLower; i < count; i += srcCount) {
        srcChar = (int)value[offset+i];
        if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
            (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
        srcChar = codePointAt(i);
        srcCount = Character.charCount(srcChar);
        } else {
            srcCount = 1;
        }
            if (localeDependent) {
                upperChar = ConditionalSpecialCasing.toUpperCaseEx(this, i, locale);
            } else {
                upperChar = Character.toUpperCaseEx(srcChar);
            }
            if ((upperChar == Character.ERROR) ||
                (upperChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
                if (upperChar == Character.ERROR) {
                    if (localeDependent) {
                        upperCharArray =
                            ConditionalSpecialCasing.toUpperCaseCharArray(this, i, locale);
                    } else {
                        upperCharArray = Character.toUpperCaseCharArray(srcChar);
                    }
                } else if (srcCount == 2) {
            resultOffset += Character.toChars(upperChar, result, i + resultOffset) - srcCount;
            continue;
                } else {
                    upperCharArray = Character.toChars(upperChar);
        }

                /* Grow result if needed */
                int mapLen = upperCharArray.length;
        if (mapLen > srcCount) {
                    char[] result2 = new char[result.length + mapLen - srcCount];
                    System.arraycopy(result, 0, result2, 0,
                        i + resultOffset);
                    result = result2;
        }
                for (int x=0; x<mapLen; ++x) {
                    result[i+resultOffset+x] = upperCharArray[x];
                }
                resultOffset += (mapLen - srcCount);
            } else {
                result[i+resultOffset] = (char)upperChar;
            }
        }
        return new String(0, count+resultOffset, result);
    }



------解决方案--------------------
只是一个标签名
------解决方案--------------------
楼上的正确,
这是带标签的break语句,用来跳出多重循环用的。
scan仅仅是一个标签名,与"break scan;"这一句中的scan对应,
当然了可以改成任意别的。
------解决方案--------------------