2 Kotlin basics

This chapter covers

  • Declaring functions, variables, classes, enums, and properties
  • Control structures in Kotlin
  • Smart casts
  • Throwing and handling exceptions

In this chapter, you’ll learn the basics of the Kotlin language required to write your first working Kotlin programs. These include basic building blocks that you encounter all throughout Kotlin programs, like variables and functions. You’ll also get acquainted with different ways of representing data in Kotlin via enums as well as classes and their properties.

The control structures you’ll learn throughout this chapter will give you the tools needed to use conditional logic in your programs as well as iterate using loops. You will also learn what makes these constructs ...

Get Kotlin in Action, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.