search

Home  >  Q&A  >  body text

java的基本数据类型的包装类是引用类型吗?

巴扎黑巴扎黑2766 days ago599

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-04-18 10:39:36

    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.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:39:36

    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

    reply
    0
  • Cancelreply