Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 41172 invoked from network); 22 Aug 2002 06:35:26 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 22 Aug 2002 06:35:26 -0000 Received: (qmail 21898 invoked by uid 97); 22 Aug 2002 06:36:01 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 21876 invoked by uid 97); 22 Aug 2002 06:36:00 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 21860 invoked by uid 98); 22 Aug 2002 06:36:00 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) X-Qmail-Scanner-Mail-From: baliuka@centras.lt via jim.skynet.vl X-Qmail-Scanner: 1.03 (Clean. Processed in 1.433923 secs) Message-ID: <054d01c249a6$1a9b7670$0111010a@user> From: "Juozas Baliuka" To: "Jakarta Commons Developers List" Cc: References: <004701c24971$a75542b0$2c00a8c0@YellowJacket> Subject: Re: [VOTE] (3b) XxxUtilsConstructors last chance Date: Thu, 22 Aug 2002 08:35:27 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N > protected StringUtils loadStringUtility(String className) throws > Exception > { > // Get the Class object for the fully qualified class name. > Class c = Class.forName(className); > // Now get an instance of that class using its public no args ctor. > return (StringUtils) c.newInstance(); > } > > The className parameter might come from a configuration file, or user > specified option. The StringUtils instance returned by this example > method might be used only via introspection, meaning that access to > any methods defined by a sub-class would be allowed without casting. You do not need "public exdendable" in this case : protected Object loadAnyUtility(String className) throws Exception /*, SecurityException */ { // Get the Class object for the fully qualified class name. Class c = Class.forName(className); // Now get an instance of that class using its any no args ctor. Constructor constructor =c.getDeclaredConstructor( new Class[]{}); constructor.setAccessible(true); // do not need to cast for introspection return constructor.newInstance( new Object[]{} ); } > > Making the class final or removing the no arguments constructor > effectively removes the ability to use the class in this fashion. So > far, the majority of arguments for taking this path revolve around "a > book told me to" or "it breaks my idea of how static classes are > used", while arguments against this path point out real world use > cases (like this one) that, while not necessarily common, are > completely valid. > -- > > Daniel Rall > > -- > To unsubscribe, e-mail: > For additional commands, e-mail: > -- To unsubscribe, e-mail: For additional commands, e-mail: