For every parameter declared in a method declaration, a new parameter variable is created each time that method is invoked. The new variable is initialized with the corresponding argument value from the method invocation.
规范中说每次方法调用,方法中的参数都会初始化。
上面test方法的index就是初始化了一个Integer类型的变量然后指向传入的i。后面的index = new Integer(20); 只是改变了index变量的指向,原来i的指向并没有改变。
引用JVM规范中的一段,详情参见
规范中说每次方法调用,方法中的参数都会初始化。
上面
test方法的index就是初始化了一个Integer类型的变量然后指向传入的i。后面的index = new Integer(20);只是改变了index变量的指向,原来i的指向并没有改变。