gpt4 book ai didi

android - 如何在 Kotlin 中使用 Realm 的 in 方法

转载 作者:太空宇宙 更新时间:2023-11-03 12:15:20 27 4
gpt4 key购买 nike

我正在尝试做类似的事情:

val barcodes = arrayOf("123", "456", "789")
realm.where(Product::class.java).in("barcode", barcodes).findAll()

但是“in”是一个 Kotlin 函数,我无法访问 RealmQuery 对象的 in(String filedName, String[] values) 方法。

目前我有一个 java 类可以完成这项工作并返回结果,但我想知道是否有更优雅的解决方法?

最佳答案

Escaping for Java identifiers that are keywords in Kotlin 中所述:

Some of the Kotlin keywords are valid identifiers in Java: in, object, is, etc. If a Java library uses a Kotlin keyword for a method, you can still call the method escaping it with the backtick (`) character

例如:

realm.where(Product::class.java).`in`("barcode", barcodes).findAll()

关于android - 如何在 Kotlin 中使用 Realm 的 in 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39820668/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com