vladimir123 vladimir123 - 1 year ago 119
Android Question

How to use Realm's in method with Kotlin

I'm trying to do something like:

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

However "in" is a Kotlin function and I can't access the in(String filedName, String[] values) method of RealmQuery object.

Currently I have a java class that does the job and returns the result, but I was wondering is there a more graceful workaround for this?

Answer Source

As stated in the 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

For example:

realm.where(Product::class.java).`in`("barcode", barcodes).findAll()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download