java 8 字符串池_字符串常量池中的"java"是哪来的

String s1 = new StringBuilder().append("计算机").append("软件").toString();

System.out.println(s1.intern() == s1);

String s2 = new StringBuilder().append("ja").append("va").toString();

System.out.println(s2.intern() == s2);

输出结果

true

false

第一个true我能理解,但是那个为什么第二个是false呢,书里面说“java”在stringbuilder.tostring()之前已经出现过。我javap查看后

Constant pool:

#1 = Methodref #14.#27 // java/lang/Object."":()V

#2 = Class #28 // java/lang/StringBuilder

#3 = Methodref #2.#27 // java/lang/StringBuilder."":()V

#4 = String #29 // 计算机

#5 = Methodref #2.#30 // java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;

#6 = String #31 // 软件

#7 = Methodref #2.#32 // java/lang/StringBuilder.toString:()Ljava/lang/String;

#8 = Fieldref #33.#34 // java/lang/System.out:Ljava/io/PrintStream;

#9 = Methodref #35.#36 // java/lang/String.intern:()Ljava/lang/String;

#10 = Methodref #37.#38 // java/io/PrintStream.println:(Z)V

#11 = String #39 // ja

#12 = String #40 // va

#13 = Class #41 // TestPool

#14 = Class #42 // java/lang/Object

#15 = Utf8

#16 = Utf8 ()V

#17 = Utf8 Code

#18 = Utf8 LineNumberTable

#19 = Utf8 main

#20 = Utf8 ([Ljava/lang/String;)V

#21 = Utf8 StackMapTable

#22 = Class #43 // "[Ljava/lang/String;"

#23 = Class #44 // java/lang/String

#24 = Class #45 // java/io/PrintStream

#25 = Utf8 SourceFile

#26 = Utf8 TestPool.java

#27 = NameAndType #15:#16 // "":()V

#28 = Utf8 java/lang/StringBuilder

#29 = Utf8 计算机

#30 = NameAndType #46:#47 // append:(Ljava/lang/String;)Ljava/lang/StringBuilder;

#31 = Utf8 软件

#32 = NameAndType #48:#49 // toString:()Ljava/lang/String;

#33 = Class #50 // java/lang/System

#34 = NameAndType #51:#52 // out:Ljava/io/PrintStream;

#35 = Class #44 // java/lang/String

#36 = NameAndType #53:#49 // intern:()Ljava/lang/String;

#37 = Class #45 // java/io/PrintStream

#38 = NameAndType #54:#55 // println:(Z)V

#39 = Utf8 ja

#40 = Utf8 va

#41 = Utf8 TestPool

#42 = Utf8 java/lang/Object

#43 = Utf8 [Ljava/lang/String;

#44 = Utf8 java/lang/String

#45 = Utf8 java/io/PrintStream

#46 = Utf8 append

#47 = Utf8 (Ljava/lang/String;)Ljava/lang/StringBuilder;

#48 = Utf8 toString

#49 = Utf8 ()Ljava/lang/String;

#50 = Utf8 java/lang/System

#51 = Utf8 out

#52 = Utf8 Ljava/io/PrintStream;

#53 = Utf8 intern

#54 = Utf8 println

#55 = Utf8 (Z)V

请问那个最初的“java”字面量在哪?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值