当前位置:网站首页>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 = 10
Equivalent toInteger i = Integer.valueOf(10)
int n = i
Equivalent 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;
}
边栏推荐
- Development of fire power monitoring system
- Development of fire evacuation system
- 307. Range Sum Query - Mutable
- Getting started with shell programming
- Project cost management__ Topic of comprehensive calculation
- Electronic product design
- Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
- Fundamentals of Electronic Technology (III)__ Fundamentals of circuit analysis__ Basic amplifier operating principle
- Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
- 单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了
猜你喜欢
[CSDN]C1训练题解析_第四部分_Web进阶
MySQL environment variable configuration
How does the memory database give full play to the advantages of memory?
How does the nr-prach receiver detect the relationship between prembleid and Ta
UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding
嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走
SSB Introduction (PbCH and DMRs need to be supplemented)
numpy. Reshape() and resize() functions
Code word in NR
Idea remote breakpoint debugging jar package project
随机推荐
Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
2020-08-23
Project cost management__ Plan value_ Earned value_ Relationship among actual cost and Countermeasures
Getting started with JMX, MBean, mxbean, mbeanserver
Matlab reads hexadecimal numbers and converts them into signed short
Quelle langue choisir pour programmer un micro - ordinateur à puce unique
Leetcode daily question (931. minimum falling path sum)
自动装箱与拆箱了解吗?原理是什么?
Mysql database underlying foundation column
Development of electrical fire system
Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode
STM32 serial communication principle
Stm32-hal library learning, using cubemx to generate program framework
Flink learning notes (VIII) multi stream conversion
万字手撕七大排序(代码+动图演示)
【22毕业季】我是毕业生yo~
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 4 --blinker_ DHT_ WiFi (lighting technology app control + temperature and humidity data app display)
JMX、MBean、MXBean、MBeanServer 入门
STM32 serial port usart1 routine
[combinatorics] Introduction to Combinatorics (context of combinatorics | skills of combinatorics | thought of combinatorics 1: one-to-one correspondence)