String Templates

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

Gabriel Shanahan
The Kotlin Primer
Published in
2 min readSep 11, 2022

--

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

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:

--

--