最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Are there potential issues with Kotlin's PublishedApi annotation? - Stack Overflow

programmeradmin10浏览0评论

I have learned how to use Kotlin's PublishedApi decorator so that I can call an internal function from a public inline function like so:

inline fun <reified T: Any> publicFun(){
    internalHelper(T::class)
}

@PublishedApi
internal fun <T : Any> internalHelper(clazz: KClass<T>){
    // do stuff
}

As the PublishedApi documentation states:

the declaration becomes effectively public, and this should be considered with respect to binary compatibility maintaining.

I have been told that, since the internal function becomes "effectively public" that changes to the internalHelper function could result in ABI changes that could be breaking to consumers of this library. Which could present issues.

But at the same time, my understanding is that the PublishedApi does not allow a consuming to library to actually access internalHelper. So I don't see how this could cause issues.

I'm trying to understand if it is "safe" to use PublishedApi in a library, or if it could lead to any subtle, nasty issues in the future. What's the deal here?

I have learned how to use Kotlin's PublishedApi decorator so that I can call an internal function from a public inline function like so:

inline fun <reified T: Any> publicFun(){
    internalHelper(T::class)
}

@PublishedApi
internal fun <T : Any> internalHelper(clazz: KClass<T>){
    // do stuff
}

As the PublishedApi documentation states:

the declaration becomes effectively public, and this should be considered with respect to binary compatibility maintaining.

I have been told that, since the internal function becomes "effectively public" that changes to the internalHelper function could result in ABI changes that could be breaking to consumers of this library. Which could present issues.

But at the same time, my understanding is that the PublishedApi does not allow a consuming to library to actually access internalHelper. So I don't see how this could cause issues.

I'm trying to understand if it is "safe" to use PublishedApi in a library, or if it could lead to any subtle, nasty issues in the future. What's the deal here?

Share Improve this question asked Mar 24 at 17:39 J-bobJ-bob 9,13613 gold badges57 silver badges89 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

But at the same time, my understanding is that the PublishedApi does not allow a consuming to library to actually access internalHelper.

Not directly, of course, but if a consuming library includes a call to publicFun, then the compiled version of their code will call internalHelper -- because publicFun, of course, got inlined.
If internalHelper gets changed, then the compiled version of that library may stop working.

发布评论

评论列表(0)

  1. 暂无评论