为什么我不能在typealias上使用@PublishedApi?

时间:2017-07-31 06:40:11

标签: kotlin

在我目前的项目中,我有一个用于不同类型查询的公共界面

interface Query<T>

以及该接口的内部实现。由于我有公共内联函数来创建不同的查询,我需要在该类上使用@PublishedApi

@PublishedApi
internal class QueryImpl<T> : Query<T>

现在为了方便起见,我想为不同类型的查询定义一些类型别名。

typealias MatchQuery = Query<MatchQueryProperties>

这对于该公共接口非常有效但我需要在我的公共内联函数中创建它的一个实例

inline fun match(init: MatchQuery.() -> Unit) {
    // It would look nicer if I could use MatchQueryImpl().init()
    QueryImpl<MatchQueryProperties>().init()
}

但是,我不想为每种查询编写QueryImpl<PropertiesType>,而是希望为实现使用内部类型。

// 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>

所以我的问题是:
我可以以某种方式使用@PublishedApi internal typealias吗?
如果不是为什么我不能使用一个?
是否存在另一种存档方式?

1 个答案:

答案 0 :(得分:1)

目前,您无法在公共内联函数中使用非公共类型。 目前的缺点是内联函数如何检查是否可以在其体内使用非公共API。

我已经打开了一个问题KT-19407来跟踪和讨论这个问题。