Simple/elegant way to do object to object transformation in Java?
<p>I have to take over and improve/finish some code that transforms Java objects from a third party library into internal objects. Currently this is done through a big if-else statement along the lines of:</p>

<pre><code>if (obj instanceOf X)
{
    //code to initialize internal object
}
else if (obj instanceOf Y)
{
    //code to initialize different object
}
else if (obj instanceOf Z)
{
    //more init code
}
...
</code></pre>

<p>Personally I don't find this solution satisfactory; it's long and messy and to make matters worse many of the if-else blocks contain more if-else blocks dealing with subclasses and edge cases. Is there a better solution to this problem?</p>
