Book Image

Mastering Android Development with Kotlin

By : Miloš Vasić
Book Image

Mastering Android Development with Kotlin

By: Miloš Vasić

Overview of this book

Kotlin is a programming language intended to be a better Java, and it's designed to be usable and readable across large teams with different levels of knowledge. As a language, it helps developers build amazing Android applications in an easy and effective way. This book begins by giving you a strong grasp of Kotlin's features in the context of Android development and its APIs. Moving on, you'll take steps towards building stunning applications for Android. The book will show you how to set up the environment, and the difficulty level will grow steadily with the applications covered in the upcoming chapters. Later on, the book will introduce you to the Android Studio IDE, which plays an integral role in Android development. We'll use Kotlin's basic programming concepts such as functions, lambdas, properties, object-oriented code, safety aspects, type parameterization, testing, and concurrency, which will guide you through writing Kotlin code in production. We'll also show you how to integrate Kotlin into any existing Android project.
Table of Contents (24 chapters)
Title Page
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Working with data classes


In Kotlin, it's recommended to use data classes as the representation for your entities. In our case, we did not use data classes since we extended a common class containing the attributes shared between the Note and Todo classes.

We recommend the use of data classes since it can significantly simplify your work routine, especially if you are using these entities in backend communication.

It's not rare that we have a need for classes that have only one purpose--holding the data. The benefit of using data classes is that some functionality that is often used along with its purpose is automatically provided. As you probably already know how to define a data class, you have to do something like this:

   data class Entity(val param1: String, val param2: String) 

For the data class, the compiler automatically provides you with the following:

  • The equals() and hashCode() methods
  • The toString() method in human readable form,Entity(param1=Something, param2=Something)
  • The copy(...