https://kotlinlang.org logo
#announcements
Title
# announcements
l

liminal

06/21/2017, 4:17 AM
Hi All, how can I define a top-level typealias that can be used by other classes and functions from various packages? For instance I want
typealias Dict<V> = Map<String, V>
to be made available to other classes
s

strelok

06/21/2017, 4:20 AM
liminal: Just declare it at top level in any
.kt
file
l

liminal

06/21/2017, 4:22 AM
So I cannot re-use this typealias definition in my project? Ideally it would be defined in one place and used whenever I need to use it within my project.
s

strelok

06/21/2017, 4:25 AM
com/test/SomeFile.kt
Copy code
typealias Dict<V> = Map<String, V> // this line can be in any file

data class ClassA(val d: Dict<String>)
com/test/subpackage/SomeOtherFile.kt
Copy code
import com.test.Dict

data class ClassB(val d: Dict<String>)
💯 1
so ofcourse you can re-use it
l

liminal

06/21/2017, 4:30 AM
great. i had wrong syntax trying to import it before. thanks!
s

strelok

06/21/2017, 4:32 AM
don't code in Notepad 😄 code in IntelliJ
👍 2
it would just import it for you
2 Views