如何创建仅包含已更改字段的增量对象?
我必须编写一个通用实用程序类,它执行以下操作:
输入:同一类的 2 个对象 - 旧的和新的
输出:与输入相同类的 1 个对象,仅包含更改的字段 - delta
不确定是否存在任何现有的框架就在那里。我更喜欢使用 Scala,但即使是 Java 也可以。
I have to write a common utility class that does following:
Input: 2 objects of the same class - old and new
Output: 1 object of the same class as Inputs, with only the fields that change - delta
Not sure if there is any existing framework out there. I would prefer to use Scala, but even Java is ok.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果对象是bean,那么您可以使用 java.beans API。它允许您通过 内省器。您需要迭代 objA 和 objB 的所有字段、比较值并在 objRes 上设置值。此外,类类型必须有一个默认构造函数。
If the objects are beans, then you can use the java.beans API. It lets you query what the fields of the bean are, via Introspector. It would be up to you to iterate over all the fields of objA and objB, comparing values, and setting values on objRes. Also, the class type would have to have a default constructor.