https://kotlinlang.org logo
#android
Title
# android
c

chris.zou

05/23/2017, 8:17 AM
Hi there, I wonder if there is a way that I can calculate the diff between two objects? Say, I have a
person1 = Person(name = "chris", age = 18)
, and
person2 = Person(name = "chris", age = 20)
, Is there a way that I can check the diff between person1 and person2 is property
age
, besides checking the properties one-by-one myself?
d

David W

05/23/2017, 8:18 AM
chris.zou: Doubtful. It's not even clear what a diff would mean, in this case.
Is it the number of properties that are different? Or do you subtract all integers...and do something with the strings?
m

mg6maciej

05/23/2017, 8:21 AM
There are a couple of libs that help with that. Here is one I found quickly: https://github.com/SQiShER/java-object-diff
👍 1
c

chris.zou

05/23/2017, 8:21 AM
In my case, I just want to know the properties(or “keys” in a JS-like sense) that are different.
m

mg6maciej

05/23/2017, 8:22 AM
And these are usually in implementation of assertion libraries like assertj.
c

chris.zou

05/23/2017, 8:23 AM
@mg6maciej That is great. I’ll take a look, thank you!
5 Views