-1

I understand the basic Java bytecode instructions and how fields are referred from the constant pool. But I cannot make my mind around the differences between these 2 lines:

java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;  

What is the concrete difference?
The only change is the part between parenthesis specifying an array of string in the first one and an integer primitive in the second one.
The first one seems to be called only once at the beginning whereas the second one is called at each new entry.

EDIT:
This is the actual concerned source code. I use it to pretty print a tree.

System.out.println(String.format("%" + this.indent + "s", "") +  "├──── " + nodeToString(currNode));

where nodeToString is a method returning a String type.

Thanks for enlightenment

Ben
  • 337
  • 4
  • 10
  • are you always appending with the same string? – Angel Koh Apr 28 '18 at 01:38
  • I edited the question for clarity. I think the compiler is using StringBuilder as an optimization as it's not effective to concatenate strings. But I still don't understand the 2 lines. – Ben Apr 28 '18 at 10:11
  • 1
    The first overload takes a `String` not an array. Type signature for array of `String` would use a left-bracket: `[Ljava.lang.String;`. – dave_thompson_085 Apr 28 '18 at 12:19
  • Thanks for precision Dave. I did not catch at first that the parentheses were specifying the function signature. Now I know :) – Ben Apr 28 '18 at 18:27

1 Answers1

0

Sorry I just needed a night of rest.
The field in parenthesis should indicate the type of the operand that is appended.
The "%" is a String and ident is an integer.
Thanks @Angel Koh you made me precise ma question it solved it all.
For whom interested here's a link describing the 2 different versions of StringBuilder:
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/StringBuilder.java

Ben
  • 337
  • 4
  • 10