CrazYmonkeY159
Expert Member
Hi guys
So I have a quick question. I have two classes in Java, they are almost identical (except one or two different methods) both are named differently for semantic reasons. but both have the same setter and getter methods and both have the same instance variables.
That being said. Is there any clever way for me to translate one object to another without going through all the setters or getters?
I'm asking because 1) I want to learn how to do this 2) I want to see if there is a simpler way than just doing it the long way. To clarify
lets say I have two classes:
If anyone can point me in the right direction that would be great. If the solution exists then i've been googling the wrong search terms
So I have a quick question. I have two classes in Java, they are almost identical (except one or two different methods) both are named differently for semantic reasons. but both have the same setter and getter methods and both have the same instance variables.
That being said. Is there any clever way for me to translate one object to another without going through all the setters or getters?
I'm asking because 1) I want to learn how to do this 2) I want to see if there is a simpler way than just doing it the long way. To clarify
lets say I have two classes:
[table="width: 500"]
[tr]
[td]
[td]
[/tr]
[/table]
[tr]
[td]
Class A:
int name
int surname
String getSurname()
void setSurname()
String getName()
void setName()
//--other methods specific to class A
[/td]int name
int surname
String getSurname()
void setSurname()
String getName()
void setName()
//--other methods specific to class A
[td]
Class B:
int name
int surname
String getSurname()
void setSurname()
String getName()
void setName()
//--other methods specific to class B
[/td]int name
int surname
String getSurname()
void setSurname()
String getName()
void setName()
//--other methods specific to class B
[/tr]
[/table]
If anyone can point me in the right direction that would be great. If the solution exists then i've been googling the wrong search terms