String的+

public class Test {
    public void test(){
        String ss="aaa"+"bbb"+"ccc";
    }
    public void yyyy(){
        String o="bbb";
        String ss="aaa"+o+"ccc";
    }
    public void xxxx(){
        String tt="";
        tt+="aaa";
        tt+="bbb";
        tt+="ccc";
    }
}
C:\Users\***>javap -v Test.class
Classfile /C:/Users/***/Test.class
  Last modified 2017-7-12; size 635 bytes
  MD5 checksum 36f408af7481f6ce1a69797b2b6a3d9b
  Compiled from "Test.java"
public class Test
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Methodref          #12.#22        // java/lang/Object."<init>":()V
   #2 = String             #23            // aaabbbccc
   #3 = String             #24            // bbb
   #4 = Class              #25            // java/lang/StringBuilder
   #5 = Methodref          #4.#22         // java/lang/StringBuilder."<init>":()V
   #6 = String             #26            // aaa
   #7 = Methodref          #4.#27         // java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
   #8 = String             #28            // ccc
   #9 = Methodref          #4.#29         // java/lang/StringBuilder.toString:()Ljava/lang/String;
  #10 = String             #30            //
  #11 = Class              #31            // Test
  #12 = Class              #32            // java/lang/Object
  #13 = Utf8               <init>
  #14 = Utf8               ()V
  #15 = Utf8               Code
  #16 = Utf8               LineNumberTable
  #17 = Utf8               test
  #18 = Utf8               yyyy
  #19 = Utf8               xxxx
  #20 = Utf8               SourceFile
  #21 = Utf8               Test.java
  #22 = NameAndType        #13:#14        // "<init>":()V
  #23 = Utf8               aaabbbccc
  #24 = Utf8               bbb
  #25 = Utf8               java/lang/StringBuilder
  #26 = Utf8               aaa
  #27 = NameAndType        #33:#34        // append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
  #28 = Utf8               ccc
  #29 = NameAndType        #35:#36        // toString:()Ljava/lang/String;
  #30 = Utf8
  #31 = Utf8               Test
  #32 = Utf8               java/lang/Object
  #33 = Utf8               append
  #34 = Utf8               (Ljava/lang/String;)Ljava/lang/StringBuilder;
  #35 = Utf8               toString
  #36 = Utf8               ()Ljava/lang/String;
{
  public Test();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 1: 0

  public void test();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=2, args_size=1
         0: ldc           #2                  // String aaabbbccc
         2: astore_1
         3: return
      LineNumberTable:
        line 3: 0
        line 4: 3

  public void yyyy();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=2, locals=3, args_size=1
         0: ldc           #3                  // String bbb
         2: astore_1
         3: new           #4                  // class java/lang/StringBuilder
         6: dup
         7: invokespecial #5                  // Method java/lang/StringBuilder."<init>":()V
        10: ldc           #6                  // String aaa
        12: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        15: aload_1
        16: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        19: ldc           #8                  // String ccc
        21: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        24: invokevirtual #9                  // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
        27: astore_2
        28: return
      LineNumberTable:
        line 6: 0
        line 7: 3
        line 8: 28

  public void xxxx();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=2, locals=2, args_size=1
         0: ldc           #10                 // String
         2: astore_1
         3: new           #4                  // class java/lang/StringBuilder
         6: dup
         7: invokespecial #5                  // Method java/lang/StringBuilder."<init>":()V
        10: aload_1
        11: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        14: ldc           #6                  // String aaa
        16: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        19: invokevirtual #9                  // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
        22: astore_1
        23: new           #4                  // class java/lang/StringBuilder
        26: dup
        27: invokespecial #5                  // Method java/lang/StringBuilder."<init>":()V
        30: aload_1
        31: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        34: ldc           #3                  // String bbb
        36: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        39: invokevirtual #9                  // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
        42: astore_1
        43: new           #4                  // class java/lang/StringBuilder
        46: dup
        47: invokespecial #5                  // Method java/lang/StringBuilder."<init>":()V
        50: aload_1
        51: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        54: ldc           #8                  // String ccc
        56: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        59: invokevirtual #9                  // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
        62: astore_1
        63: return
      LineNumberTable:
        line 10: 0
        line 11: 3
        line 12: 23
        line 13: 43
        line 14: 63
}
SourceFile: "Test.java"

C:\Users\***>
posted @ 2017-07-12 12:45  元页  阅读(341)  评论(0编辑  收藏  举报