java的基本数据类型的包装类是引用类型吗?
巴扎黑
巴扎黑 2017-04-18 10:37:36
0
2
562
巴扎黑
巴扎黑

reply all(2)
刘奇

Quoting a paragraph from the JVM specification, see

for details

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.

The specification says that every time a method is called, the parameters in the method will be initialized.

The direction of test方法的index就是初始化了一个Integer类型的变量然后指向传入的i。后面的index = new Integer(20); 只是改变了index变量的指向,原来i above has not changed.

Ty80

Methods in Java all use value transfer. Even if it is a reference, what is passed is a copy of the original reference

The method can only change the attributes in the parameter reference, but not the reference address of the parameter

And you can see the source code of Integer:

The value it wraps is modified by final, that is, it can only be assigned once, and the value will not change after the assignment.

Also, you can try other reference types to see if they can be changed, such as String

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!