Kotlin 为什么可以';我不能在typealias上使用@PublishedApi吗?
在我当前的项目中,我有一个用于不同类型查询的公共接口Kotlin 为什么可以';我不能在typealias上使用@PublishedApi吗?,kotlin,Kotlin,在我当前的项目中,我有一个用于不同类型查询的公共接口 interface Query<T> 现在为了方便起见,我想为不同类型的查询定义一些类型别名 typealias MatchQuery = Query<MatchQueryProperties> typealias MatchQuery=Query 这对于该公共接口非常有效,但我需要在我的公共内联函数中创建它的一个实例 inline fun match(init: MatchQuery.() -> Unit
interface Query<T>
现在为了方便起见,我想为不同类型的查询定义一些类型别名typealias MatchQuery = Query<MatchQueryProperties>
typealias MatchQuery=Query
这对于该公共接口非常有效,但我需要在我的公共内联函数中创建它的一个实例
inline fun match(init: MatchQuery.() -> Unit) {
// It would look nicer if I could use MatchQueryImpl().init()
QueryImpl<MatchQueryProperties>().init()
}
内联趣味匹配(init:MatchQuery.(->单位){
//如果我能使用MatchQueryImpl().init()会更好
QueryImpl().init()
}
但是,我不必为每种查询编写QueryImpl
,我还希望在实现中使用内部类型别名
// fails because it needs to be internal
typealias MatchQueryImpl = QueryImpl<MatchQueryProperties>
// can't be used in public inline functions
internal typealias MatchQueryImpl = QueryImpl<MatchQueryProperties>
// annotation can't be used on typealias
@PublishedApi internal typealias MatchQueryImpl = QueryImpl<MatchQueryProperties>
//失败,因为它需要是内部的
typealias MatchQueryImpl=QueryImpl
//不能在公共内联函数中使用
内部类型别名MatchQueryImpl=QueryImpl
//无法在typealias上使用批注
@PublishDAPI内部类型别名MatchQueryImpl=QueryImpl
所以我的问题是:我是否可以使用
@PublishedApi内部类型别名
如果不是,为什么我不能用呢
是否有其他方法存档我想要的内容?目前,您不能在公共内联函数中使用非公共typealias。 这是内联函数检查是否可以在其主体内使用非公共API的当前缺点 我打开了一个问题来跟踪和讨论这个问题
// fails because it needs to be internal
typealias MatchQueryImpl = QueryImpl<MatchQueryProperties>
// can't be used in public inline functions
internal typealias MatchQueryImpl = QueryImpl<MatchQueryProperties>
// annotation can't be used on typealias
@PublishedApi internal typealias MatchQueryImpl = QueryImpl<MatchQueryProperties>