Book Image

Programming Kotlin

Book Image

Programming Kotlin

Overview of this book

Quickly learn the fundamentals of the Kotlin language and see it in action on the web. Easy to follow and covering the full set of programming features, this book will get you fluent in Kotlin for Android.
Table of Contents (20 chapters)
Programming Kotlin
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Interfaces


An interface is nothing more than a contract; it contains definitions for a set of related functionalities. The implementer of the interface has to adhere to the interface the contract and implement the required methods. Just like Java 8, a Kotlin interface contains the declarations of abstract methods as well as method implementations. Unlike abstract classes, an interface cannot contain state; however, it can contain properties. For the Scala developer reading this book, you will find this similar to the Scala traits:

    interface Document { 
      val version: Long   
      val size: Long 
 
      val name: String     
      get() = "NoName" 
 
      fun save(input: InputStream) 
      fun load(stream: OutputStream) 
      fun getDescription(): String { 
         return "Document $name has $size byte(-s)"} 
    } 

This interface defines three properties and three methods; the name property and the getDescription methods...