<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	>
<channel>
	<title>Comments on: From String to any primitive type in 4 lines of code</title>
	<atom:link href="http://devfunk.com/2009/04/01/from-string-to-any-primitive-type-in-4-lines-of-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://devfunk.com/2009/04/01/from-string-to-any-primitive-type-in-4-lines-of-code/</link>
	<description></description>
	<pubDate>Fri, 30 Jul 2010 18:29:28 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Raibaz</title>
		<link>http://devfunk.com/2009/04/01/from-string-to-any-primitive-type-in-4-lines-of-code/comment-page-1/#comment-331</link>
		<dc:creator>Raibaz</dc:creator>
		<pubDate>Mon, 15 Jun 2009 12:18:30 +0000</pubDate>
		<guid isPermaLink="false">http://devfunk.com/?p=64#comment-331</guid>
		<description>I know NumberFormat is better for string to number conversions, but i tend to prefer this approach whenever there is need for extensibility and the set of types to be created isn't known in advance.

Whenever the type set to be created is fixed, as the latest two comments have noticed, a more specific approach is probably better, but this one IMHO wins when generality is required.</description>
		<content:encoded><![CDATA[<p>I know NumberFormat is better for string to number conversions, but i tend to prefer this approach whenever there is need for extensibility and the set of types to be created isn&#8217;t known in advance.</p>
<p>Whenever the type set to be created is fixed, as the latest two comments have noticed, a more specific approach is probably better, but this one IMHO wins when generality is required.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Lawrey</title>
		<link>http://devfunk.com/2009/04/01/from-string-to-any-primitive-type-in-4-lines-of-code/comment-page-1/#comment-330</link>
		<dc:creator>Peter Lawrey</dc:creator>
		<pubDate>Mon, 15 Jun 2009 06:35:58 +0000</pubDate>
		<guid isPermaLink="false">http://devfunk.com/?p=64#comment-330</guid>
		<description>This is a good tip.

The downside of the funky solution is that its is very inefficient.  I have one helper method which does this ugly, but efficient way and I call that, and so hides the "crappy" way.

If you want to support conversion of other types you may find that the String constructor is either not there or doesn't do what you would want.

Useful text conversions include Enum, and DateTime,a dn you can support String[], Integer[], List, Map

I prefer to use the caches for Boolean, Integer, Long rather than creating new object every time.

I treat "NaN" as NaN, and empty String as null in most cases.</description>
		<content:encoded><![CDATA[<p>This is a good tip.</p>
<p>The downside of the funky solution is that its is very inefficient.  I have one helper method which does this ugly, but efficient way and I call that, and so hides the &#8220;crappy&#8221; way.</p>
<p>If you want to support conversion of other types you may find that the String constructor is either not there or doesn&#8217;t do what you would want.</p>
<p>Useful text conversions include Enum, and DateTime,a dn you can support String[], Integer[], List, Map</p>
<p>I prefer to use the caches for Boolean, Integer, Long rather than creating new object every time.</p>
<p>I treat &#8220;NaN&#8221; as NaN, and empty String as null in most cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ran Biron</title>
		<link>http://devfunk.com/2009/04/01/from-string-to-any-primitive-type-in-4-lines-of-code/comment-page-1/#comment-329</link>
		<dc:creator>Ran Biron</dc:creator>
		<pubDate>Sun, 14 Jun 2009 18:16:46 +0000</pubDate>
		<guid isPermaLink="false">http://devfunk.com/?p=64#comment-329</guid>
		<description>Ugh. WRONG, WRONG!!!

You're circumventing caches, using reflection for simple lookups and giving up proper exceptions. Probably more, but I stopped counting.

Use java.text.NumberFormat for proper string to number conversions, and add a single check for Double.NaN.</description>
		<content:encoded><![CDATA[<p>Ugh. WRONG, WRONG!!!</p>
<p>You&#8217;re circumventing caches, using reflection for simple lookups and giving up proper exceptions. Probably more, but I stopped counting.</p>
<p>Use java.text.NumberFormat for proper string to number conversions, and add a single check for Double.NaN.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dfa</title>
		<link>http://devfunk.com/2009/04/01/from-string-to-any-primitive-type-in-4-lines-of-code/comment-page-1/#comment-328</link>
		<dc:creator>dfa</dc:creator>
		<pubDate>Sat, 13 Jun 2009 19:20:03 +0000</pubDate>
		<guid isPermaLink="false">http://devfunk.com/?p=64#comment-328</guid>
		<description>I used this for many years:

Class number;
T zero = (T) number.getConstructor(String.class).newInstance("0");</description>
		<content:encoded><![CDATA[<p>I used this for many years:</p>
<p>Class number;<br />
T zero = (T) number.getConstructor(String.class).newInstance(&#8221;0&#8243;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://devfunk.com/2009/04/01/from-string-to-any-primitive-type-in-4-lines-of-code/comment-page-1/#comment-327</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Sat, 13 Jun 2009 18:56:49 +0000</pubDate>
		<guid isPermaLink="false">http://devfunk.com/?p=64#comment-327</guid>
		<description>Wow! Nice! I will try that now .. ;-)</description>
		<content:encoded><![CDATA[<p>Wow! Nice! I will try that now .. <img src='http://devfunk.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
