Skip to content

Commit 6f28541

Browse files
nit: redundant call to sb.toString before print
'Command line arguments' chapter ends with the following code snippet: ... sb.toString println(sb) and those two lines IMHO should be replaced with one as: * 'sb.toString' performs actual string materialisation from buffer and returns it, but nothing is actually using it * 'println(sb)' relies on StringBuilder having properly implemented 'toString' method (which is obviously the case) and calls it implicitly again and prints it to the std out this time I have proposed to reduce it to 'println(sb.toString)' to give clear intent of 'toString' being actually used to produce the content that is outputted but 'println(sb)' would do to.
1 parent a3a5f45 commit 6f28541

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

_overviews/scala3-book/methods-main-methods.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ For example, given this `@main` method that takes an `Int`, a `String`, and a va
4949

5050
val sb = StringBuilder(s"Happy $age$suffix birthday, $name")
5151
for other <- others do sb.append(" and ").append(other)
52-
sb.toString
53-
println(sb)
52+
println(sb.toString)
5453
```
5554

5655
When you compile that code, it creates a main program named `happyBirthday` that’s called like this:

0 commit comments

Comments
 (0)