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

I have learned how to use Kotlin's PublishedApi decorator so that I can call an internal function

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744236420a4564491.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信