O'Reilly logo

Kotlin in Action by Svetlana Isakova, Dmitry Jemerov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 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 how to declare in Kotlin the essential elements of any program: variables, functions, and classes. Along the way, you’ll get acquainted with the concept of properties in Kotlin.

You’ll learn how to use different control structures in Kotlin. They’re mostly similar to those that are familiar to you from Java, but enhanced in important ways.

We’ll introduce the concept of smart casts, which combine a type check and a cast into one operation. Finally, we’ll talk about exception handling. By the end of this chapter, you’ll be able ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required