commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Rall <>
Subject Re: [VOTE] (3b) XxxUtilsConstructors last chance
Date Thu, 22 Aug 2002 00:30:54 GMT
"Steven Caswell" <> writes:

> I confess I'm a novice in the area of class loading. Can you elaborate a
> little more?  What do you mean by "utility class extensions"?

By "utility class extensions", I'm talking about literally extending,
say, StringUtils, for instance.  I might have code like this:

  protected StringUtils loadStringUtility(String className) throws
      // 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.

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: <>

View raw message