RealmObject: Impossible to implement interfaces
Having added "implements" clause to one of my RealmObjects, I am facing the following exception:
Caused by: io.realm.exceptions.RealmException: Could not find io.realm.RealmJsonImpl
...
Caused by: java.lang.ClassNotFoundException: io.realm.RealmJsonImpl
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "io.realm.RealmJsonImpl" on path: DexPathList[[zip file "/data/app/com.example.app-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.app-2/lib/x86, /vendor/lib, /system/lib]]
Removing implements clause makes my app useable again.
So it sounds like we can't add implements clause to an object extending RealmObject, can we?
PS. The code is like:
public class AwesomeStuff extends RealmObject implements IAwesomeInterface {
//some fields
private String field;
//some getters/setters for them, standard java getter/setter naming convention
public String getField(){
return field;
}
@Overrides
public String someAwesomeMethod(){
//call getter method to return some value
return getField();
}
}
Custom methods are not allowed in RealmObjects for now. So interfaces would not work. Follow #637 for details. What version are you using by the way? 0.80.0 should not even build with this setup.
Thanks for pointing out.
I use 0.80.0, no error/warning is issued in build log.
At least, I hope I got it right that static methods are supported in RealmObject subclasses now?
It is not transparent from documentation whether they are allowed, though it works for me. Wouldn't want to fall victim of this ambiguity in future.
Provide more details about your classes and build log. It may be a bug that no error or warning emitted.
static methods are supported.
In my code I am able to implement interfaces. The interfaces just can't have methods different from those generated by realm
Hi @ousenko What @iflatness says is true. Currently we don't allow any custom class methods except getters and setters. Using interfaces with no methods should work, the same with static methods/fields.
And it looks like we should update the documentation to be more clear :)
One thing I would like to add: interfaces with methods matching the getters and setters do work. @cmelchior can you confirm this?
Yes, empty interfaces or interfaces with methods that match getters and setters work just fine currently.