Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe11.iad.POSTED!00000000!not-for-mail From: David Lamb User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Class.forName().newInstance() vs new References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 10 Message-ID: <9SNIp.6968$5v5.253@newsfe11.iad> NNTP-Posting-Host: 67.193.237.254 X-Complaints-To: abuse@cogeco.net X-Trace: newsfe11.iad 1307814405 67.193.237.254 (Sat, 11 Jun 2011 17:46:45 UTC) NNTP-Posting-Date: Sat, 11 Jun 2011 17:46:45 UTC Date: Sat, 11 Jun 2011 13:46:42 -0400 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5207 On 11/06/2011 1:13 PM, Abu Yahya wrote: > My question is: Does using if-else statements like the above really > improve performance? What is the best approach to instantiate classes > whose type you don't know at compile time? That code is unlikely to be in some critical inner loop, so any efficiency gains would be marginal. Your original solution requires no change if the possible classes change and is simpler to understand, each of which on its own wins out over marginal gains in efficiency.