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

Instantiating classes


Creating an instance of a class will be familiar to readers who have experience of object-orientated programming. The syntax in many languages uses a new keyword followed by the name of the class to be created. The new keyword indicates to the compiler that the special constructor function should be invoked to initialize the new instance.

Kotlin, however, removes this ceremony. It treats calling a constructor function the same as a normal function, with the constructor function using the name of the class. This enables Kotlin to drop the new keyword entirely. Arguments are passed in as normal:

    val file = File("/etc/nginx/nginx.conf") 
    val date = BigDecimal(100)