Java for loop by value or by reference

前端 未结 6 805
忘了有多久
忘了有多久 2020-12-10 04:37

I figured out a a problem in my Code. First the code:

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
           


        
6条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 05:10

    When you want to do a low level optimization, know how, you have to look inside Java code and inside byte-code either(compiled code)

    for(String s : blablubb) {
                s = "over";
    }
    

    is equals with:

    for (int i = 0; i < blablubb.length; i++) {
         String s = blablubb[i];            
         s = "over";
    }
    

    and that's why the output as how it is.

提交回复
热议问题