The Solution: import ... as ...

Kotlin has a simple solution for this: import aliases. Akin to how we use as for type aliases, we can use as to assign an alias to an import:

import android.databinding.Observable
import io.reactivex.Observable as RxObservable

Now, we can use RxObservable instead of io.reactivex.Observable.

This can be a bit confusing, as casual code reviewers might not notice the import alias and might not recognize the alias name. However, particularly when you use an IDE for working with Kotlin, finding the source of the alias usually is easy enough, and the alias usually is less cumbersome than is the fully-qualified class name.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.