String 对象
2020-08-05 14:26:07 0 举报
java String 底层 内存模型
作者其他创作
大纲/内容
\"abc\"
编译过程
使用intern方法,内存中会创建该对象,然后将对象的引用加入到常量池中
堆
栈
intern
0: ldc #2 // String Andy 2: astore_1 3: ldc #3 // String 24 5: astore_2 6: ldc #4 // String Developer 8: astore_3 9: new #5 // class java/lang/StringBuilder 12: dup 13: invokespecial #6 // Method java/lang/StringBuilder.\"<init>\":()V 16: aload_1 17: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 20: aload_2 21: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 24: aload_3 25: invokevirtual #7 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; 28: invokevirtual #8 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
String str = new String(\"abc\");String str2 = \"hello\";
str
str2
常量池 “abc”\"hello\"
String a=\"abc\";String b=\"def\";String c=\"abcdef\";String d=a+b;System.out.println(c==d)创建了四个对象
0 条评论
下一页