Hi there, I wonder if there is a way that I can ca...
# android
c
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
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
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
In my case, I just want to know the properties(or “keys” in a JS-like sense) that are different.
m
And these are usually in implementation of assertion libraries like assertj.
c
@mg6maciej That is great. I’ll take a look, thank you!