Kotlin - Statement Imports

Introduction

To import the required class, object, interface, or function:

import com.java2s.myproject.Foo 

Wildcard imports

To avoid specifying each import individually we can import the entire package at once using the * operator:

import com.java2s.myproject.* 

Wildcard imports are useful to import helper functions or constants are defined at the top level.

//definition
package com.java2s.myproject.constants 

val PI = 3.142 
val E = 2.178 

//importing
package com.java2s.myproject 
import com.java2s.myproject.constants.* 

fun add() = E + PI 

Related Topics