Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom implementations for toString, equals and hashCode #1480

Merged
merged 7 commits into from
Aug 16, 2023

Conversation

cmelchior
Copy link
Contributor

@cmelchior cmelchior commented Aug 10, 2023

Closes #1097

This PR adds custom toString, equals, and hashCode implementations to Realm Object subclasses. If these methods already exist, nothing will be generated.

TODO

  • Finish testing
  • RealmSet support
  • RealmDictionary support (created a new issue)

@cmelchior cmelchior marked this pull request as ready for review August 14, 2023 07:11
@cmelchior cmelchior requested a review from rorbech August 14, 2023 07:11
Copy link
Contributor

@rorbech rorbech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I left some minor comments here and there.

@@ -58,48 +50,6 @@ class RealmModelSyntheticCompanionExtension : SyntheticResolveExtension {
}
}

override fun addSyntheticSupertypes(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure that these are safe to delete. I think it was added because the default implementation is no longer part of the interface (aka related to the changed jvm-default mode) in https://github.com/realm/realm-kotlin/pull/1163/files. But maybe ok now that we compile against 1.8+ which we also run against 🤔 ... I guess it should be safe.

@Suppress("unused", "MagicNumber") // Called from generated code
// Inlining this functions somehow break the IntelliJ debugger, unclear why?
internal fun realmHashCode(obj: BaseRealmObject): Int {
// This code assumes no race conditions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put some notes about the side effects of this: Not thread safe on live objects or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should, but not sure where it would make sense?

@cmelchior cmelchior merged commit 364f546 into main Aug 16, 2023
1 check passed
@cmelchior cmelchior deleted the cm/custom-equals-hashcode branch August 16, 2023 06:57
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RealmObject equals are probably not correct
2 participants