-3
所以在這種方法中,while循環的條件是我選擇刪除行代碼並創建一個方法,在需要時調用。但是,這第一種方法不起作用,並導致應用程序無聲鎖定。爲什麼這個方法調用工作,但不是在編寫代碼?
def getLineRows(rows, index) {
def lineRows = [rows[index]]
def newOperator
def i = index + 1
if (index <= (rows.size() - 1)) {
newOperator = false
這是有問題的代碼。
while (index <= (rows.size() - 1) && !newOperator) {
if (rows[index].PGM_PROC_OPE.trim() == "" ||
(rows[index].PGM_PROC_TY == "OR" ||
rows[index].PGM_PROC_TY == "AN")) {
lineRows << rows[i]
} else {
newOperator = true
}
i++
}
}
return lineRows
}
在這第二個和視覺上相同的方法中,我簡單地創建了一個名爲moreRows(rows,index)的方法。還有兩個方法調用,但是他們已經通過測試從考慮中消除。
def moreRows(rows, index) {
return index <= (rows.size() - 1)
}
什麼會導致低於該代碼才能正常工作時moreRows被使用,而不是由上述的方法中,其中moreRows爲線?
def getLineRows(rows, index) {
def lineRows = [rows[index]]
def newOperator
def i = index + 1
if (moreRows(rows, i)) {
newOperator = false
while (moreRows(rows, i) && !newOperator) {
if (operatorEmpty(rows, i) || isSpecialProcType(rows, i)) {
lineRows << rows[i]
} else {
newOperator = true
}
i++
}
}
return lineRows
}
謝謝,就是這樣。當我將代碼從方法切換到內聯時,我沒有注意到我需要與i進行比較而不是索引。謝謝! – kschmit90 2015-01-26 20:24:18