admin管理员组

文章数量:1405636

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.

本文标签: Are there potential issues with Kotlin39s PublishedApi annotationStack Overflow