https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
u

ursus

08/14/2019, 12:23 AM
Hi, has anyone tried to automate generating DiffUtil.Callback methods? Mostly `areContentsTheSame`and
getChangePayload
) Say I have a model, the usual case fo areItemsEqual is to use equals(), but what if I dont want to compare all the fields? So, I could write a reflection util / codegen for this, but it requires to have some sort of a @Exclude annotation on a given field *which in turn means that our data/domain layer Foo model knows about diff util stuff so not sure if this is the way to go* should it maybe be manual code and keep reflection (traversing all the fields) unit test to check if new fields are added) (edited) -- or, create a UI layer level model from it, and use just the plain equals from it (or not, doesnt matter, since now diffutil annotations make sense)
r

rkeazor

08/18/2019, 2:30 PM
Umm you can you use a annotation processor. and add annotations for the comparable fields
2 Views