From 6f285416853c671517a64d55076a719411fcfa9f Mon Sep 17 00:00:00 2001 From: JC Date: Wed, 6 Jul 2022 18:32:35 +0200 Subject: [PATCH] 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. --- _overviews/scala3-book/methods-main-methods.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_overviews/scala3-book/methods-main-methods.md b/_overviews/scala3-book/methods-main-methods.md index e30da56dcd..07a1f225c3 100644 --- a/_overviews/scala3-book/methods-main-methods.md +++ b/_overviews/scala3-book/methods-main-methods.md @@ -49,8 +49,7 @@ For example, given this `@main` method that takes an `Int`, a `String`, and a va val sb = StringBuilder(s"Happy $age$suffix birthday, $name") for other <- others do sb.append(" and ").append(other) - sb.toString - println(sb) + println(sb.toString) ``` When you compile that code, it creates a main program named `happyBirthday` that’s called like this: