当前位置:网站首页>Whether the modification of basic type and reference type is valid
Whether the modification of basic type and reference type is valid
2022-06-12 06:23:00 【Fishbone CC】
public class TestTransferValue {
public void changeValue1(int age){// copy 3
age = 30;// What is modified is also a copy
}
public void changeValue2(Person person){
person.setPersonName("xxx");
}
public void changeValue3(String str){
str = "xxx";
}
public static void main(String[] args) {
TestTransferValue test = new TestTransferValue();
int age = 20; // ( For basic types ) original script 1
test.changeValue1(age);// Pass the copy in 2
System.out.println("age----"+age); // At this moment, the output is the original 4
Person person = new Person("abc");
test.changeValue2(person);
System.out.println("personName----"+person.getPersonName());
String str = "abc"; //abc In the constant pool
test.changeValue3(str);
System.out.println("String----"+str);
}
}
result : age----20
personName----xxx
String----abc
Person person( Point to person Type references ) = new Person(“abc”);( example )

Spread changeValue3 When it's inside str Point to abc,r then str="xxx" You need to find... From the constant pool first xxx, Create in constant pool if not found xxx, then str Point to xxx, At this time, the output is still output main Method str, It still points to abc, And new changeValue Inside str Equivalent to not using .
summary : Pass the basic type unchanged , Transfer reference type change
边栏推荐
- MNIST handwritten data recognition by RNN
- (UE4 4.27) customize globalshader
- Simple spiral ladder generation for Houdini program modeling
- [reinstall system] 01 system startup USB flash disk production
- Textcnn (MR dataset - emotion classification)
- SQL注入——联合查询union
- JS变量作用域
- RNN model
- How to increase heap size of JVM [duplicate] - how to increase heap size of JVM [duplicate]
- 基于报错的 SQL 注入
猜你喜欢

Multithreading mode (I) -- protective pause and join source code

SQL 注入-盲注

C2w model - language model

MNIST handwritten data recognition by CNN

AI作业ch8

. Net core - pass Net core will Net to cross platform

分段贝塞尔曲线

Sqlite Cross - compile Dynamic Library

勤于奋寻找联盟程序方法介绍

Directx11 advanced tutorial PBR (1) summary of physical phenomena of light
随机推荐
单通道图片的读入
Research Report on truffle fungus industry - market status analysis and development prospect forecast
Sqlite Cross - compile Dynamic Library
Sensor bringup 中的一些问题总结
leetcode 704. Binary search
Qt-- realize TCP communication
Opencv_100问_第五章 (21-25)
Nodemon cannot load the file c:\users\administrator\appdata\roaming\npm\nodemon PS1, because script execution is prohibited in this system
基于报错的 SQL 注入
Bert use
线程有哪些状态?
Explanation of sensor flicker/banding phenomenon
Univariate linear regression model
LeetCode-剑指Offer(第二版)个人题解完整版
Unity3d multi platform method for reading text files in streamingasset directory
Overview of camera image quality
What states do threads have?
LeetCode-1185. Day of the week
RNN implementation regression model
Open the camera in unity3d and display the contents of the camera in the scene as texture2d