avatarGabriel Shanahan

Summary

This article provides a comprehensive explanation of literals in Kotlin, including examples and Kotlin Primer guide references.

Abstract

The web content introduces the concept of literals in the Kotlin programming language, offering a refresher on what literals are and providing examples of integer, string, object, and function literals. It emphasizes the importance of understanding literals for the subsequent sections of the Kotlin Primer guide. The article, which is part of the Kotlin Primer series intended to facilitate Kotlin adoption in Java-centric organizations, includes interactive Kotlin Playground embeds for practical demonstrations of different types of literals. Readers are encouraged to familiarize themselves with the concept of literals to better grasp the upcoming content in the guide.

Opinions

  • The author believes that understanding literals is crucial for readers to follow the subsequent sections of the Kotlin Primer.
  • The article is written with the intent to make Kotlin concepts easy to understand, suggesting that the topic of literals may be complex or overlooked by learners.
  • The author expresses gratitude to Etnetera a.s. for supporting the creation of the Kotlin Primer, indicating a collaborative effort behind the guide.
  • Readers are advised to read the Introduction and Table of Contents for a structured learning path, highlighting the guide's educational approach.
  • The inclusion of interactive Kotlin Playground examples demonstrates the author's commitment to providing hands-on learning experiences.
  • The article's tone suggests that the topic of literals, while theoretical, is presented in a way that is engaging and relevant to the reader's learning journey.

Literals

A refresher on what a literal is, and examples of integer, string, object and function literals (and also what literals are not) in Kotlin

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

THE CURRENT VERSION OF THIS ARTICLE IS PUBLISHED HERE.

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

Tags: #FYI

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.

This is one of those theoretical-wibbly-wobbly-timey-wimey things we need to talk about briefly so that we understand each other in the following sections.

The word “literal” is one of those words that you see all over the place, but never really paid much attention to because it didn’t play an important role in understanding whatever it was you were reading.

That’s fine, normally it’s not really important, but in the following sections, we’re going to keep mentioning ‘function literals’. Since the whole point of the Primer is to make Kotlin easy to understand, I thought I’d include this section. That way, you won’t have to pretend like you know what I’m actually talking about, and can focus all your energy on pretending like you care.

A ‘literal’ is what you call a notation (= a piece of text = a piece of code that’s been written down) that can be used to create an instance of a type “in that place”. That notation (= text = code) “literally is” the object. Literals are expressions, i.e. they can be assigned.

The examples bellow should make clear what we mean — you don’t have to read all of them, just as long as you understand what a literal is.

A full breakdown of literals in Kotlin can be found in the docs.

Number literals

String literals

Array & object literals

Function literals

Go back to Types, jump to the Table of Contents, or continue to Functions Types & Literals.

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