Mic*_*sel 8 kotlin kotlin-multiplatform
我正在尝试将我的 Android 库转换为 Kotlin 多平台库。
我想保留的一件事是所有针对 Android Lint 的 android 特定注释。我能够通过做一些简单的事情来转换其中的大部分,比如
@MustBeDocumented
@Retention(AnnotationRetention.BINARY)
@Target(
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.CONSTRUCTOR,
AnnotationTarget.ANNOTATION_CLASS,
AnnotationTarget.CLASS,
AnnotationTarget.VALUE_PARAMETER
)
expect annotation class MainThread()
actual typealias MainThread = androidx.annotation.MainThread
Run Code Online (Sandbox Code Playgroud)
这不起作用,RestrictTo因为它需要一个论点。
androidRestrictTo注释看起来像
@Retention(CLASS)
@Target({ANNOTATION_TYPE,TYPE,METHOD,CONSTRUCTOR,FIELD,PACKAGE})
public @interface RestrictTo {
/**
* The scope to which usage should be restricted.
*/
Scope[] value();
enum Scope {
}
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法让编译器对值的类型感到满意。
如果我让期望看起来像
@Target(
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.FIELD,
AnnotationTarget.CONSTRUCTOR,
AnnotationTarget.ANNOTATION_CLASS,
AnnotationTarget.CLASS
)
@MustBeDocumented
@Retention(AnnotationRetention.BINARY)
expect annotation class RestrictTo(vararg val value: RestrictScope)
Run Code Online (Sandbox Code Playgroud)
我收到编译错误
Run Code Online (Sandbox Code Playgroud)public expect final val value: Array<out RestrictScope /* = RestrictTo.Scope */> The following declaration is incompatible because return type is different: public final val value: Array<RestrictTo.Scope>
如果我将值从可变参数更改为数组,则会出现此错误。
Run Code Online (Sandbox Code Playgroud)public constructor RestrictTo(value: Array<RestrictScope /* = RestrictTo.Scope */>) The following declaration is incompatible because parameter types are different: public constructor RestrictTo(vararg value: RestrictTo.Scope)
有没有办法让类型同时适用于构造函数和值方法?
| 归档时间: |
|
| 查看次数: |
448 次 |
| 最近记录: |