简体   繁体   English

在Kotlin中覆盖Java @Nullable varargs方法时,IDE抱怨它没有覆盖任何内容

[英]Overriding a Java @Nullable varargs method in Kotlin, IDE complains it overrides nothing

I've got a Java method interface that looks something like this: 我有一个看起来像这样的Java方法接口:

@NonNull Future<List<Item>> search(@NonNull String query, @Nullable EntityType... types);

and when I implement it in Kotlin like this (via IntelliJ implementation generation): 当我这样在Kotlin中实现它时(通过IntelliJ实现生成):

override fun search(query: String, vararg roomType: EntityType?): Future<List<Item>>

the IDE complains that it "overrides nothing". IDE抱怨说它“没有覆盖任何内容”。 However, if the @Nullable annotation didn't exist in the Java class, there are no lint errors. 但是,如果Java类中不存在@Nullable批注,则不会出现皮棉错误。

The annotation is labeling the array of varargs as nullable, not the values within the array. 注释将可变参数数组标记为可为空,而不是数组中的值。 This seems to work: 这似乎可行:

override fun search(query: String, roomType: Array<EntityType>?): Future<List<Item>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM