Book Image

Android Development with Kotlin

By : Igor Wojda, Marcin Moskala
Book Image

Android Development with Kotlin

By: Igor Wojda, Marcin Moskala

Overview of this book

Nowadays, improved application development does not just mean building better performing applications. It has become crucial to find improved ways of writing code. Kotlin is a language that helps developers build amazing Android applications easily and effectively. This book discusses Kotlin features in context of Android development. It demonstrates how common examples that are typical for Android development, can be simplified using Kotlin. It also shows all the benefits, improvements and new possibilities provided by this language. The book is divided in three modules that show the power of Kotlin and teach you how to use it properly. Each module present features in different levels of advancement. The first module covers Kotlin basics. This module will lay a firm foundation for the rest of the chapters so you are able to read and understand most of the Kotlin code. The next module dives deeper into the building blocks of Kotlin, such as functions, classes, and function types. You will learn how Kotlin brings many improvements to the table by improving common Java concepts and decreasing code verbosity. The last module presents features that are not present in Java. You will learn how certain tasks can be achieved in simpler ways thanks to Kotlin. Through the book, you will learn how to use Kotlin for Android development. You will get to know and understand most important Kotlin features, and how they can be used. You will be ready to start your own adventure with Android development with Kotlin.
Table of Contents (16 chapters)
Title Page
About the Authors
About the Reviewers
Customer Feedback
Making Your Marvel Gallery Application

Function types

Kotlin supports functional programming, and functions are first-class citizens in Kotlin. A first-class citizen in a given programming language is a term that describes an entity that supports all the operations generally available to other entities. These operations typically include being passed as an argument, returned from a function, and assigned to a variable. The sentence a function is a first-class citizen in Kotlin should then be understood as: it is possible in Kotlin to pass functions as an argument, return them from functions, and assign them to variables. While Kotlin is a statically typed language, there needs to be a function type defined to allow these operations. In Kotlin, the notation used to define a function type is the following:

    (types of parameters)->return type 

Here are some examples:

  • (Int)->Int: A function that takes Int as an argument and returns Int
  • ()->Int: A function that takes no arguments and returns Int
  • (Int)->Unit: A function that...