当前位置:网站首页>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;
}
边栏推荐
- 万字手撕七大排序(代码+动图演示)
- Qt QComboBox QSS样式设置
- 我想各位朋友都应该知道学习的基本规律就是:从易到难
- Introduction to chromium embedded framework (CEF)
- Install local sources using yum
- Nr-prach:prach format and time-frequency domain
- SCM career development: those who can continue to do it have become great people. If they can't endure it, they will resign or change their careers
- PIP references domestic sources
- 内存数据库究竟是如何发挥内存优势的?
- How MySQL modifies null to not null
猜你喜欢

MYSQL数据库底层基础专栏

Getting started with JMX, MBean, mxbean, mbeanserver

Embedded systems are inherently flawed. Compared with the Internet, there are so many holes that it is simply difficult to walk away from

MySQL Data Definition Language DDL common commands

UCI and data multiplexing are transmitted on Pusch - placement of data and UCI positions (Part III)

SSB Introduction (PbCH and DMRs need to be supplemented)
![[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)

You need to use MySQL in the opening experiment. How can you forget the basic select statement? Remedy is coming~

MySQL data manipulation language DML common commands

JMX、MBean、MXBean、MBeanServer 入门
随机推荐
307. Range Sum Query - Mutable
SCM career development: those who can continue to do it have become great people. If they can't endure it, they will resign or change their careers
uniapp 实现微信小程序全局分享及自定义分享按钮样式
Install local sources using yum
Electronic product design
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
Matlab reads hexadecimal numbers and converts them into signed short
MySQL 数据库基础知识(系统化一篇入门)
Stm32-hal library learning, using cubemx to generate program framework
[untitled] proteus simulation of traffic lights based on 89C51 Single Chip Microcomputer
[combinatorics] Introduction to Combinatorics (combinatorial thought 2: mathematical induction | mathematical induction promotion | multiple induction thought)
Shell logic case
干单片机这一行的时候根本没想过这么多,只想着先挣钱养活自己
[CSDN] C1 training problem analysis_ Part II_ Web Foundation
Getting started with shell programming
Electronic product design, MCU development, circuit cloning
Raspberry pie installation SciPy
Successful graduation [3]- blog system update...
2021-01-03
编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解