Inline function cannot access non-public-API: @PublishedApi vs @Suppress vs @JvmSynthetic

前端 未结 1 1056
梦如初夏
梦如初夏 2020-12-05 17:49

In Kotlin, when I have a non-public member and an inline fun that calls it, there\'s a compilation error saying:

Error:(22, 25) Kotlin: Publ

相关标签:
1条回答
  • 2020-12-05 18:19

    @PublishedApi internal is the intended way of exposing non-public API for using in public inline functions.

    That @PublishedApi internal member becomes effectively public and its name doesn't get mangled (if you noticed the opposite, please file a bug).

    @Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE") is a band-aid workaround in the lack of @PublisedApi based on suppressing an error and therefore isn't recommended. With the introduction of @PublishedApi this suppression is going to be cleaned from stdlib.

    @JvmSynthetic combined with @PublishedApi is an interesting approach, however it can cause some problems while debugging, though I'm not sure.

    0 讨论(0)
提交回复
热议问题