当前位置:网站首页>String STR = new string ("ABC") how many variables are created?
String STR = new string ("ABC") how many variables are created?
2022-07-22 09:18:00 【Flowers bloom without knowing you】
String str = new String(“abc”) Created several variables ?
My answer is 1 A or 2 individual
Why? ? The process is as follows
Look in the constant pool for “abc” object
If yes, the corresponding reference instance is returned
If not, create the corresponding instance object
In the heap new One String(“abc”) object
Assign the object address to str4, Create a reference
So the constant pool has "abc" Only one instance object is created , Otherwise, one more object will be created in the constant pool
that String str1 = new String(“A”+“B” ) How many objects will be created ?
I think it's the same as above
Because the compiler will Automatic optimization
become
String str1 = new String(“AB”) ;
It can be downloaded from Bytecode From the perspective of
public static main([Ljava/lang/String;)V
L0
LINENUMBER 11 L0
NEW java/lang/String
DUP
LDC "AB"
INVOKESPECIAL java/lang/String.<init> (Ljava/lang/String;)V
ASTORE 1
L1
LINENUMBER 12 L1
RETURN
L2
LOCALVARIABLE args [Ljava/lang/String; L0 L2 0
LOCALVARIABLE s Ljava/lang/String; L1 L2 1
MAXSTACK = 3
MAXLOCALS = 2
}
ps: Where is the string constant pool ? Method area ?
jdk1.6 There is a method area . In the method area Runtime constant pool
, This period String constant pool
In the runtime constant pool , Static variables are also in the method area ..
jdk1.7 Put the string constant pool and static variables To the pile
.
jdk1.8 Change the method area to Meta space
Separate from the virtual machine memory to the local memory , Dan word String constant pool
The pool is still there Pile up
in
and Runtime constant pool
Moved to Meta space
.
Of course , All the above is just a personal summary by reading the articles of other bosses , Welcome to discuss !
边栏推荐
- flex布局
- 真人踩过的坑,告诉你避免自动化测试新手常犯的10个错误
- MMDrawerController 获取当前VC进行Push和Pop
- Gradle 15分钟入门教程
- Shortcut keys for command line editing and operation skills commands
- jq移除某个元素样式
- Union keyword in SQL
- Obstacles au partage des connaissances et solutions
- 华泰证券渠道开户安全吗,怎么看是不是正规
- Implementation of recommendation system collaborative filtering in spark
猜你喜欢
随机推荐
js获取对象属性值
Literature learning (part98) -- pseudosupervised deep subspace clustering
面试题 01.02. 判定是否互为字符重排
分库分表的数据存储方案思路
详解flex布局
华泰证券渠道开户安全吗,怎么看是不是正规
Redis learning notes
Configure opencv in QT
数据格式化小组件
flex布局
AFNetworking data-raw请求方式
Use style to solve the white border when the irregular screen is horizontal
类加载器简介
Leetcode342:4 power
Es version i9-13900k appeared, CPU-Z database score data is too modest
Is it safe to open an account at Huatai Securities? Where is it more reliable
JDBC事务操作
Single cell paper records (Part17) -- integrating SC transcriptomic data across different conditions, technology and specialties
Documentation (part108) -- distributive robot and multi objective nonnegative matrix factorization
推荐系统-协同过滤在Spark中的实现