问题描述
大家好,
我想检测对象中的变量是否发生了变化。就像输出布尔数组的方法一样,每个字段都有一个布尔值,用于确定字段在上次更新时是否发生了变化。
我不想使用属性,因为我的类有90个字段。因此,为每个字段写一个属性会很痛苦。
我的第一个应用是复制对象的最后一个状态并将其与更新的状态进行比较。但是复制和比较的过程也很复杂,因为我不想使用鸭子复制方法来复制它(出于同样的原因我不想使用属性)而且比较实际上并不是真的因为我必须为我在对象中使用的所有类重写equals方法。
我的第二个方法是序列化我的对象,更新它并再次序列化它并比较我得到的两个字节流。但是我不喜欢这个,因为每次更新都需要两次才能实现,所以它会非常快地消耗我的资源。
你觉得我能做什么?有效地解决这个问题吗?
Hello folks,
I want to detect if variables in an object has changed. Like an method that outputs an boolean array, so one boolean for each field, that determins if the field has changed in the last update.
I don't want to use properties, as my class has 90 fields. So to write an property for each field would be a pain.
My first approche was to copy the last state of the object and compare it with the updated one. But the process of copying and comparing would be also complicated, as I don't want to use a duck copy method to copy it (for the same reason I don't want to use properties) and also the comparing isn't really practically as I would have to override the equals method for all classes I used in my object.
My second approche was to serialise my object, update it and than serialise it again and compare the two byte streams i got. But I don't like this either as I would have to serealize it twice per update, so it would consume my resources really fast.
What do you think I could do to solve this problem effectively?
推荐答案
这篇关于检查对象中的变量是否已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!