Collection类中的奇怪控制语句

jel*_*ion 1 java java-api

我在Java API Collection类中遇到了这段代码.它是否像switch语句一样工作?这个成语是怎么称呼的?

public static int indexOfSubList(List<?> source, List<?> target) {
    int sourceSize = source.size();
    int targetSize = target.size();
    int maxCandidate = sourceSize - targetSize;

    if (sourceSize < INDEXOFSUBLIST_THRESHOLD ||
        (source instanceof RandomAccess&&target instanceof RandomAccess)) {
    nextCand:
        for (int candidate = 0; candidate <= maxCandidate; candidate++) {
            for (int i=0, j=candidate; i<targetSize; i++, j++)
                if (!eq(target.get(i), source.get(j)))
                    continue nextCand;  // Element mismatch, try next cand
            return candidate;  // All elements of candidate matched target
        }
    } else {  // Iterator version of above algorithm
        ListIterator<?> si = source.listIterator();
    nextCand:
        for (int candidate = 0; candidate <= maxCandidate; candidate++) {
            ListIterator<?> ti = target.listIterator();
            for (int i=0; i<targetSize; i++) {
                if (!eq(ti.next(), si.next())) {
                    // Back up source iterator to next candidate
                    for (int j=0; j<i; j++)
                        si.previous();
                    continue nextCand;
                }
            }
            return candidate;
        }
    }
    return -1;  // No candidate matched the target
}
Run Code Online (Sandbox Code Playgroud)

rad*_*dai 5

不,它只是一个标记的休息/继续.看这里:

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html

Java允许使用标签作为中断/继续目标.默认情况下,中断/继续将影响其最内层循环,但使用标签可以突破外部循环.