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

Imports


To enable classes, objects, interfaces, and functions to be used outside of the declared package we must import the required class, object, interface, or function:

    import com.packt.myproject.Foo 

Wildcard imports

If we have a bunch of imports from the same package, then to avoid specifying each import individually we can import the entire package at once using the * operator:

    import com.packt.myproject.* 

Wildcard imports are especially useful when a large number of helper functions or constants are defined at the top level, and we wish to refer to those without using the classname:

    package com.packt.myproject.constants 
 
    val PI = 3.142 
    val E = 2.178 
 
    package com.packt.myproject 
    import com.packt.myproject.constants.* 
    fun add() = E + PI 

Notice how the add() function does not need to refer to E and PI using the FQN, but can simply use them as if they were in scope. The wildcard import removes the repetition...