简体   繁体   English

使用vararg调用Java函数而不是在Kotlin中编译

[英]Invoking Java function with vararg not compiling in Kotlin

I'm trying to call a Java method from Kotlin but the compiler doesn't manage to find the proper signature. 我正在尝试从Kotlin调用Java方法,但编译器无法找到正确的签名。

The method has 2 signatures : 该方法有2个签名:

Observable<Query> createQuery(@NonNull final String table, @NonNull String sql, @NonNull String... args) 

Observable<Query> createQuery(@NonNull final Iterable<String> tables, @NonNull String sql, @NonNull String... args)

Then in kotlin I just want to call this, which seems completely valid to me : 然后在kotlin我只想打电话给这个,这对我来说似乎完全有效:

db.createQuery("users", "select * from users")

But the compiler say 但是编译器说

None of the following functions can be called with the arguments supplied: 
public open fun createQuery(android.support.annotation.NonNull tables: kotlin.(Mutable)Iterable<kotlin.String!>!, android.support.annotation.NonNull sql: kotlin.String!, android.support.annotation.NonNull vararg args: kotlin.String!): rx.Observable<com.squareup.sqlbrite.SqlBrite.Query!>! defined in com.squareup.sqlbrite.BriteDatabase
public open fun createQuery(android.support.annotation.NonNull table: kotlin.String!, android.support.annotation.NonNull sql: kotlin.String!, android.support.annotation.NonNull vararg args: kotlin.String!): rx.Observable<com.squareup.sqlbrite.SqlBrite.Query!>! defined in com.squareup.sqlbrite.BriteDatabase

I read Kotlin and Java method with vararg have some interrop issues, is there a way to fix that without using a java class as a bridge ? 我阅读Kotlin和Java方法与vararg有一些插入问题,有没有办法解决这个问题而不使用java类作为桥梁?

It was because the object is of type BriteDatabase? 这是因为对象是BriteDatabase?类型的BriteDatabase? , so I have to use it with db!! ,所以我必须用它与db!! or db? 还是db? .

Maybe the error message should be improved! 也许错误信息应该改进!

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

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