当前位置:网站首页>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;
}
边栏推荐
- The third paper of information system project manager in soft examination
- There is no specific definition of embedded system
- Stm32-hal library learning, using cubemx to generate program framework
- JMX、MBean、MXBean、MBeanServer 入门
- C language enumeration type
- Quelle langue choisir pour programmer un micro - ordinateur à puce unique
- Flink learning notes (XI) table API and SQL
- UCI and data multiplexing are transmitted on Pusch (Part VI) -- LDPC coding
- 顺利毕业[2]-学生健康管理系统 功能开发中。。。
- Project scope management__ Scope management plan and scope specification
猜你喜欢

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

CEF download, compile project
![顺利毕业[3]-博客系统 更新中。。。](/img/91/72cdea3eb3f61315595330d2c9016d.png)
顺利毕业[3]-博客系统 更新中。。。

当你需要使用STM32某些功能,而51实现不了时, 那32自然不需要学

STM32 external interrupt experiment

Gpiof6, 7, 8 configuration

內存數據庫究竟是如何發揮內存優勢的?
![[combinatorics] Introduction to Combinatorics (combinatorial thought 2: mathematical induction | mathematical induction promotion | multiple induction thought)](/img/0e/dff6d3c6b7bf388bf71b0965533c25.jpg)
[combinatorics] Introduction to Combinatorics (combinatorial thought 2: mathematical induction | mathematical induction promotion | multiple induction thought)

端午节快乐!—— canvas写的粽子~~~~~
![顺利毕业[2]-学生健康管理系统 功能开发中。。。](/img/91/72cdea3eb3f61315595330d2c9016d.png)
顺利毕业[2]-学生健康管理系统 功能开发中。。。
随机推荐
Difference of EOF
当你需要使用STM32某些功能,而51实现不了时, 那32自然不需要学
2021-01-03
STM32 interrupt priority management
Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
Blue Bridge Cup for migrant workers majoring in electronic information engineering
Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
学习开发没有捷径,也几乎不存在带路会学的快一些的情况
【顺利毕业】[1]-游览 [学生管理信息系统]
How does the nr-prach receiver detect the relationship between prembleid and Ta
307. Range Sum Query - Mutable
MySQL Data Definition Language DDL common commands
要選擇那種語言為單片機編寫程序呢
STM32 interrupt switch
Intelligent home design and development
How MySQL modifies null to not null
学历是一张通行证,门票,你有了它,可以踏入更高层次的环境里
byte alignment
Idea remote breakpoint debugging jar package project
UCI and data multiplexing are transmitted on Pusch - placement of data and UCI positions (Part III)