当前位置:网站首页>Parameter passing mechanism of member methods
Parameter passing mechanism of member methods
2022-07-05 00:26:00 【The learning path of Java Rookies】
Parameter transfer mechanism of basic data type
The basic data type passes a value , The change of formal parameter value will not lead to the change of actual parameter value
public class MethodParameter01 {
// Write a main Method
public static void main(String[] args) {
int a = 10;
int b = 20;
// establish AA object name obj
AA obj = new AA();
obj.swap(a, b); // call swap
System.out.println("main Method a=" + a + " b=" + b);//a=10 b=20
}
}
class AA {
public void swap(int a,int b){
System.out.println("\na and b Value before exchange \na=" + a + "\tb=" + b);//a=10 b=20
// It's done a and b In exchange for
int tmp = a;
a = b;
b = tmp;
System.out.println("\na and b Value after exchange \na=" + a + "\tb=" + b);//a=20 b=10
}
}
Here is my memory analysis of the above code
When swap After method execution , It's out of the stack , Memory free , And then go ahead and do it main Method ,swap Formal parameters in method a,b Changes that occur do not affect changes in arguments
The parameter passing mechanism of reference data type
Memory resolution
summary
When parameters are passed , The basic data type is a value , Parameter changes do not affect argument changes
The reference data type passes the memory address , The change of formal parameters will affect the change of arguments
边栏推荐
- How to use fast parsing to make IOT cloud platform
- 他做国外LEAD,用了一年时间,把所有房贷都还清了
- Basic points of the game setup of the points mall
- Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC
- JS how to realize array to tree
- Parsing of XML
- Some basic functions of enterprise projects are developed, and important things are saved to online first a
- 电力运维云平台:开启电力系统“无人值班、少人值守”新模式
- Remember to build wheels repeatedly at one time (the setting instructions of obsidian plug-in are translated into Chinese)
- 海思3559万能平台搭建:YUV422的踩坑记录
猜你喜欢
2022.07.03(LC_6108_解密消息)
城市轨道交通站应急照明疏散指示系统设计
Date time type and format in MySQL
Face recognition 5- insight face padding code practice notes
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
A new method for analyzing the trend chart of London Silver
如何避免电弧产生?—— AAFD故障电弧探测器为您解决
Pytoch --- use pytoch to realize linknet for semantic segmentation
"Xiaodeng" domain password policy enhancer in operation and maintenance
两个数相互替换
随机推荐
What is the difference between port mapping and port forwarding
业务实现-日志写到同一个行数据里面
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
Get to know ROS for the first time
城市轨道交通站应急照明疏散指示系统设计
圖解網絡:什麼是網關負載均衡協議GLBP?
Netcore3.1 JSON web token Middleware
业务场景功能的继续修改
OpenHarmony资源管理详解
他做国外LEAD,用了一年时间,把所有房贷都还清了
巩固表达式C# 案例简单变量运算
Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
Detailed explanation of openharmony resource management
AcWing164. 可达性统计(拓扑排序+bitset)
实战模拟│JWT 登录认证
The pit of sizeof operator in C language
跨域请求
[monitoring] ZABBIX
【C】(笔试题)指针与数组,指针
Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC