java pass by value and pass by reference

1. In java, each new statement returns a reference to a pointer, but in most cases Java does not care how to operate this pointer. It should be noted that when passing an object to a function, the basic data type and Object variables, there are different operations:

  • Basic type variable: pass a copy of the value (copy changes, itself unchanged)
  • Object variable: pass a copy of the reference (the copy changes, and it changes itself) [that is, copy the pointer to the object address]

    Regardless of the type of the Java parameter, a copy of the parameter is always passed, that is, only value is passed in Java.

2. String, as well as several basic type wrapper classes such as Integer and Double, they are all immutable types. Because there is no function for self-modification, each operation generates a new object, so it needs special treatment, which can be considered as The basic data types are similar, and there is no difference between pass-by-value operations, that is, pass-by-value and pass-by-reference.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324673651&siteId=291194637