0

I guess I could write my own version of this, but I wonder if something like this already exists in Java or a well known util. Suppose I have a class

public class User {
   private String name;
   private String number;
}

and I have the following

User currentUser = new User();
currentUser.setName("Bob Smith");
currentUser.setNumber("5555555555");
User updatedUser = new User();
updatedUser.setNumber("4444444444");

I want to be able to call something like:

currrentUser.patch(updatedUser);

and end up with:

currentUser.getNumber() == "444444444";
currentUser.getName() == "Bob Smith";

So basically I want currentUser to take all the non-null values of updatedUser. In the real world User has many more members, and might even extend another class.

Leo
  • 4,652
  • 6
  • 32
  • 42

0 Answers0