當我編寫以下內容時,IntelliJ的scalastyle讓我非常不高興。它不喜歡我寫回報。scala避免返回,同時仍然短迭代
def hasAnnotation(symbol: Symbol, annotation: Type): Boolean = {
for (a <- symbol.annotations) {
if (a.tpe =:= annotation) return true // AVOID USING RETURN!!!
}
false
}
爲什麼要加回歸邪惡?
我怎樣才能快捷迭代沒有返回?
這將是很好,如果答案澄清爲什麼'易碎「被認爲是邪惡的。 https://github.com/scala/scala/blob/v2.11.8/src/library/scala/collection/TraversableLike.scala#L130關於https://github.com/scala/scala/blob/v2。 11.8/src/library/scala/collection/TraversableOnce.scala#L90 –
這裏有一些討論http://stackoverflow.com/questions/2742719/how-do-i-break-out-of-a-loop-in-斯卡拉 – user48956
是的,如下鏈接,但沒有說明我的簡單頭腦。 –