<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nito &#187; class</title>
	<atom:link href="http://blog.pirelenito.org/tag/class/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pirelenito.org</link>
	<description>Thoughts dump yard</description>
	<lastBuildDate>Tue, 20 Jul 2010 02:18:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Cloning the unclonable</title>
		<link>http://blog.pirelenito.org/2010/03/cloning-the-unclonable/</link>
		<comments>http://blog.pirelenito.org/2010/03/cloning-the-unclonable/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 23:42:30 +0000</pubDate>
		<dc:creator>nito</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[clone]]></category>
		<category><![CDATA[serialization]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://blog.pirelenito.org/?p=91</guid>
		<description><![CDATA[Sometimes during development we need to save an object state so that we can latter return to it, due to a problem or a by an user undo request. In these scenarios usually some type of cloning is a good way to go. Java has a standard way of doing this through the .clone() method, [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes during development we need to save an object state so that we can latter return to it, due to a problem or a by an user undo request. In these scenarios usually some type of cloning is a good way to go.</p>
<p>Java has a standard way of doing this through the .clone() method, but in order for it to work, the classes need to implement it explicitly. Then comes a day that you need to clone some third party object that does not implement the clone() method, so what do you do?</p>
<p>Me and friend <a href="http://besen.posterous.com/" target="_blank">Renato Besen</a> came along an interesting solution during a pair, and I thought it would be fun to share. The object we wanted to clone was Serializable, so we created a class that perform a cloning through serialization, writing the object into memory and then reading it back into another new instance, effectively making a clone of it.</p>
<p>The class is generic, so the final solution is pretty neat, just call:</p>
<p style="padding-left: 30px;">new SerializationCloner&lt;ThirdPartyClass&gt;().clone(instance);</p>
<p>And that is it! You can <a href="http://labs.pirelenito.org/experiments/svn/java/cloningutility/src/SerializationCloner.java">get the source from here</a>.</p>
<p>The only obvious downside is performance, so use it with caution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pirelenito.org/2010/03/cloning-the-unclonable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

