OnJava8-Examples icon indicating copy to clipboard operation
OnJava8-Examples copied to clipboard

About StringBuilder

Open antaow opened this issue 3 years ago • 1 comments

Bruce,

I am now a student. When I read your chapter on Strings, I found a problem: a problem about the "+" operator. In the section of Overloading + vs.StringBuilder: For the implicit() method in WhitherStringBuilder.java, I tried to use javap -c WhitherStringBuilder and found that the corresponding bytecode is like this.

 public java.lang.String implicit(java.lang.String[]);
    Code:
       0: ldc           #7                  // String
       2: astore_2
       3: aload_1
       4: astore_3
       5: aload_3
       6: arraylength
       7: istore        4
       9: iconst_0
      10: istore        5
      12: iload         5
      14: iload         4
      16: if_icmpge     40
      19: aload_3
      20: iload         5
      22: aaload
      23: astore        6
      25: aload_2
      26: aload         6
      28: invokedynamic #9,  0              // InvokeDynamic #0:makeConcatWithConstants:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
      33: astore_2
      34: iinc          5, 1
      37: goto          12
      40: aload_2
      41: areturn

Later, I checked about invokedynamic #9, 0, perhaps adding new features. Please have a look

My java version is "17.0.1" 2021-10-19 LTS

antaow avatar May 27 '22 02:05 antaow

这是来自QQ邮箱的假期自动回复邮件。您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

cdh111007 avatar May 27 '22 02:05 cdh111007