Skip to content

Kotlin: Cannot import-on-demand from object

I am trying to make a library where you can call functions of an object through “static imports” (import-on-demand in Kotlin). Unfortunately Kotlin seems to have a limitation as seen below.

enter image description here

Why is this a limitation? Is there anything I can do to get around it? (I’ve tried using a class with a companion object and in that case the functions don’t even resolve.)



Sparkot is your Kotlin class, if I understand it’s right.
Objects may inherit things from supertypes, e.g. equals(), hashCode() will be imported every time you* import from an object, and the decision was made that this would be too confusing.

* – imports work only with Java object.

8 People found this is helpful