简体   繁体   English

在Java中为每个循环调用方法吗?

[英]Calling method inside java for each loop?

I have a very basic question regarding the for loop. 关于for循环,我有一个非常基本的问题。 When we call a method (return or void) on some element inside the for each loop, does the loop waits until the method finishes or does it move on to the next element in the collection immediately? 当我们在for每个循环中的某个元素上调用一个方法(返回或作废)时,循环会一直等到该方法完成之前还是会立即移至集合中的下一个元素?

Unless the method is run in a new thread, the next iteration of the loop will not start until the previous one is completed 除非该方法在新线程中运行,否则直到下一个循环完成之前,循环的下一个迭代才会开始

That you are asking this question indicates to me that you may not fully understand the concept of the Thread stack (vs the global Heap). 您在问这个问题向我表明您可能不完全了解线程堆栈的概念(与全局堆相比)。 I'm not trying to be mean but understanding how the thread stack works is very important 我并不是要刻薄,但了解线程堆栈的工作原理非常重要

在继续下一个元素之前,它将贯穿该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM