[英]java: how many times is the collection expression evaluated in a “foreach”
if I do this in Java: 如果我在Java中这样做:
for(String s : myCollection.expensiveListGeneration())
{
doSomething();
}
is expensiveListGeneration() invoked just once at the beggining or in every cycle iteration? 是贵的ListGeneration()在开始或每个循环迭代中只调用一次?
Is it implementation dependent? 它是依赖于实现的吗?
because it is equivalent to using an iterator, it is equivalent to calling the collections' . 因为它等同于使用迭代器,它相当于调用集合'。 iterator() method, and it is called once.
iterator()方法,它被调用一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.