avatarGabriel Shanahan

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1154

Abstract

and I would like to express my sincere gratitude for their support.</p></blockquote><blockquote id="757e"><p>It is recommended to read the <a href="https://readmedium.com/introduction-2cc7eba631e2">Introduction</a> before moving on. Check out the <a href="https://readmedium.com/table-of-contents-c52573cfa291">Table of Contents</a> for all articles.</p></blockquote><p id="018f">Learn about <a href="https://kotlinlang.org/docs/strings.html#string-templates">string templates</a>, which make writing <code>toString()</code> methods a breeze (among many other things). Make special note of the fact that you can compute entire expressions inside string templates. For example, this is valid code:</p> <figure id="135b"> <div> <div> <img class="ratio" src="http://placehold.it/16x9"> <iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2Fv8wawOpPt&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2Fv8wawOpPt&amp;image=https%3A%2F%2Fplay.kotlinlang.org%2Fassets%2Fog-image.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type

Options

=text%2Fhtml&schema=kotl" allowfullscreen="" frameborder="0" height="300" width="800"> </div> </div> </figure></iframe></div></div></figure><p id="5573">It might seem impractical due to the way code gets highlighted in the Kotlin Playground, but the IDE does a much better job:</p><figure id="c1cb"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*jEGoRHypalNRHgXXhQ612g.png"><figcaption></figcaption></figure><p id="43a4">Go back to the <a href="https://readmedium.com/triple-quoted-strings-adc99888ccb0">Triple-quoted Strings</a>, jump to the <a href="https://readmedium.com/table-of-contents-c52573cfa291">Table of Contents</a>, or continue to <a href="https://readmedium.com/nullability-46d1bed24111">Nullability</a>.</p><figure id="8ecd"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*biBSB579iezsNvEQ_NMLBg.png"><figcaption><a href="https://www.etnetera.cz/prace-u-nas?utm_source=medium&amp;utm_medium=GabrielShanahan&amp;utm_campaign=KotlinPrimer&amp;utm_content=join-our-team&amp;utm_term=KotlinPrimer#pozice">Join me in Etnetera</a></figcaption></figure></article></body>

String Templates

Write toString() methods in a breeze, and compute entire expressions inside a string, using string templates

— — — — — — — — — — — — — — —

THE CURRENT VERSION OF THIS ARTICLE IS PUBLISHED HERE.

— — — — — — — — — — — — — — —

Tags: #KOTLIN FEATURE

This article is part of the Kotlin Primer, an opinionated guide to the Kotlin language, which is indented to help facilitate Kotlin adoption inside Java-centric organizations. It was originally written as an organizational learning resource for Etnetera a.s. and I would like to express my sincere gratitude for their support.

It is recommended to read the Introduction before moving on. Check out the Table of Contents for all articles.

Learn about string templates, which make writing toString() methods a breeze (among many other things). Make special note of the fact that you can compute entire expressions inside string templates. For example, this is valid code:

It might seem impractical due to the way code gets highlighted in the Kotlin Playground, but the IDE does a much better job:

Go back to the Triple-quoted Strings, jump to the Table of Contents, or continue to Nullability.

Join me in Etnetera
Kotlin
Java
Learning
Tostring
Programming
Recommended from ReadMedium