I am trying to write an adapter. I have almost 50 attributes which I’m trying to adapt from one class to another.
My code looks like:
public static Type2 getType2(Type1 type1)
{
...
if(!StringUtils.isEmpty(type1.getAttribute1()) {
type2.setAttribute1( type1.getAttribute1() );
}
// and so on for all the 50 attributes
...
}
Is there a better way to write this adapter method?
You could use a generic way to copy attributes from one instance to antoher: