Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About StringBuilder #55

Open
antaow opened this issue May 27, 2022 · 1 comment
Open

About StringBuilder #55

antaow opened this issue May 27, 2022 · 1 comment

Comments

@antaow
Copy link

antaow commented May 27, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@antaow and others