Realm Java 0.88 — Better Objects!
We just released a new version of Realm Java to this website and to Maven. This release includes many exciting new features.
Better Objects!
With this release, Realm for Android gives developers full control over their Realm objects. You will now be able to:
- Add custom methods to your objects.
- Implement interfaces.
- Add custom logic to the getters and setters.
- Name the accessors in any way you prefer.
- Skip accessors altogether and make the fields public.
- Write your own
toString()
,equals()
, andhashCode()
methods. - Combine Realm with Lombok.
This means that from now on, dealing with Realm objects will feel a lot more like handling normal POJOs.
In order to make this happen, we had to make Realm a Gradle plugin and not simply a library.
As mentioned in a previous post this means that from now on you will have to change the way you associate Realm to your project in the build.gradle
file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'io.realm:realm-gradle-plugin:0.88.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
This also means that from now on we will not support other build systems other than Gradle. If this seems unreasonable to you, we’ve already prepared two issues for you to vote on to re-introduce support for Maven and/or Ant.
Your opinion will lead our decision on whether and when we will implement Ant and Maven plugins.
Note that a few restrictions still apply to Realm objects:
- Subclassing from anything but
RealmObject
is not allowed. - Fields are not allowed to be
final
,volatile
, ortransient
.
Other Improvements
This release also brings a number of other improvements:
-
RealmQuery.distinct()
andRealmQuery.distinctAsync()
have been added. -
RealmQuery.isNotEmpty()
is now supported for Strings, lists, and byte arrays. - Realm now uses
Relinker
, which should eliminate crashes on some devices when installing apps with native code like Realm. -
Realm.deleteAll()
has been added, which can be used to clear all Realm data without deleting the file.
Breaking Changes 🚨
-
All notifications now use the Looper queue. Previously, when committing a transaction, all
RealmChangeListener
s on the same thread were triggered immediately. In order to make change listeners more predictable and consistent, they are now being delayed to the next Looper message. -
All RxJava Observables now hold a reference to the Realm instance that created them. This means that a Realm file is now only fully closed when all Observables have been unsubscribed from. It also means that it is now possible to close a Realm instance using
doOnUnsubscribe
.
See the full changelog for all the details.
Thanks for reading. Now go forth and build amazing apps with Realm! As always, we’re around on Stack Overflow, GitHub, and Twitter.