How to import all top level functions in another kotlin file

Viewed 166

I have two files, AzimuthAct.kt and Mathf.kt, all of my custom functions are in Mathf.kt.

how do you import all function to another .kt file? something like:

import com.company.appname.Mathf.* // <-- doesnt work
import kotlin.math.* // work

this what i mean

1 Answers

Top level functions are members of the package declared at the top of their containing file

In order to use them outside their own package, you can import them individually as import kotlin.math.sin or if you want to import them all then you can use star import after package name as import kotlin.math.*

In your case if you want to import all the top level functions declared in Mathf file then you need to use a star import on package as

import com.company.appname.*

Now you should be able to access all your top level functions from Mathf.kt

Related