当前位置:网站首页>Do you understand automatic packing and unpacking? What is the principle?
Do you understand automatic packing and unpacking? What is the principle?
2022-07-03 09:54:00 【look-word】
Automatic packing and unpacking understand ? What is the principle ?
What is an automatic box ?
- Packing : Wrap basic types with their corresponding reference types ;
- Unpacking : Convert wrapper type to base data type ;
give an example :
Integer i = 10; // Packing
int n = i; // Unpacking
Bytecode file
L1
LINENUMBER 8 L1
ALOAD 0
BIPUSH 10
INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
PUTFIELD AutoBoxTest.i : Ljava/lang/Integer;
L2
LINENUMBER 9 L2
ALOAD 0
ALOAD 0
GETFIELD AutoBoxTest.i : Ljava/lang/Integer;
INVOKEVIRTUAL java/lang/Integer.intValue ()I
PUTFIELD AutoBoxTest.n : I
RETURN
From bytecode , We found that boxing is actually calling The wrapper class valueOf() Method , Unpacking is actually calling xxxValue() Method .
therefore ,
Integer i = 10Equivalent toInteger i = Integer.valueOf(10)int n = iEquivalent toint n = i.intValue();
Be careful : If the box is disassembled frequently , It will also seriously affect the performance of the system . We should try to avoid unnecessary disassembly and assembly of the box
private static long sum() {
// You should use long instead of Long
Long sum = 0L;
for (long i = 0; i <= Integer.MAX_VALUE; i++)
sum += i;
return sum;
}
边栏推荐
- Convert IP address to int
- Development of fire evacuation system
- 2020-08-23
- UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding
- Flink learning notes (XI) table API and SQL
- Education is a pass and ticket. With it, you can step into a higher-level environment
- Flink CDC practice (including practical steps and screenshots)
- 单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇
- [CSDN] C1 training problem analysis_ Part IV_ Advanced web
- Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
猜你喜欢

Flink learning notes (XI) table API and SQL

Flink CDC practice (including practical steps and screenshots)

Nr--- Pusch I: sorting out the agreement process

STM32 port multiplexing and remapping

Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
![[graduation successful] [1] - tour [Student Management Information System]](/img/91/72cdea3eb3f61315595330d2c9016d.png)
[graduation successful] [1] - tour [Student Management Information System]

Development of fire evacuation system

Fundamentals of Electronic Technology (III)__ Logic gate symbols in Chapter 5

Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode

Shell logic case
随机推荐
307. Range Sum Query - Mutable
The cyclic shift of PUCCH in NR channel is generated by MATLAB
学历是一张通行证,门票,你有了它,可以踏入更高层次的环境里
STM32 serial communication principle
2020-08-23
How does the memory database give full play to the advantages of memory?
Matlab reads hexadecimal numbers and converts them into signed short
Implementing distributed lock with redis
C language enumeration type
顺利毕业[2]-学生健康管理系统 功能开发中。。。
万字手撕七大排序(代码+动图演示)
Fundamentals of Electronic Technology (III)__ Fundamentals of circuit analysis__ Basic amplifier operating principle
Intelligent home design and development
Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
在三线城市、在县城,很难毕业就拿到10K
Project cost management__ Topic of comprehensive calculation
Fundamentals of Electronic Technology (III)__ Chapter 6 combinational logic circuit
MySQL environment variable configuration
CEF download, compile project
2021-09-26