Closed cbedoy closed 6 years ago
Hi @cbedoy, you can call extensions functions from java without problems. Have you tried something like this?
List<User> result = RealmExtensionsKt.querySorted(new User(), "id", Sort.ASCENDING, new
Function1<RealmQuery<User>, Unit>() {
@Override
public Unit invoke(RealmQuery<User> query) {
query.equalTo("field", "value");
return Unit.INSTANCE;
}
});
And you can simplify this code if you use retrolambda.
Great! that works but my question is why seems my RealmQuery<<>> is ignored
override fun <T : RealmObject> querySortedObjects(_clazz: Class<T>, _fieldName: String, _order: Sort, _query: RealmQuery<T>): List<T> {
val results = _clazz.newInstance().querySorted(_fieldName, _order, {
_query //this is ignored "The expression is unused"
})
return results
}
@cbedoy You are trying to return an object inside the lambda. Lambda expression is defined as io.realm.RealmQuery
I'm using Realm Extensions but currently no all our code is on Kotlin we have several layers that will need to refactor (Java), I know extensions are not supported on java, that why I created like and Grapper on kotlin that recieve RealmQuery instead of Query
I'd like to know (if you know). How I can made the compatibility between Query injected from a java class as RealmQuery.
I'm already know that you defined as
Where I supposed if you inject a field as RealmQuery should be supported, but seems like you library ignore my RealmQuery injected cuz isn't a Query
There's my example wrapper created in Kotlin it receive a class, fieldName, order and _query
And there's my code provide from java.
Seems ignore my RealmQuery param
Then seems just perform this