commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Dudziak <tom...@gmail.com>
Subject Re: [lang] enhanced version of Class.forName
Date Tue, 06 Sep 2005 07:09:27 GMT
On 9/6/05, James Carman <james@carmanconsulting.com> wrote:

> I would say that this is something that would be very useful.  We did
> something similar in HiveMind.  I can imagine an implementation like:
> 
> private static Map typeMap = new HashMap();
> private static Map abbreviationMap = new HashMap();
> 
> static
> {
>   typeMap.put( "int", Integer.TYPE );
>   typeMap.put( "boolean", Boolean.TYPE );
>   typeMap.put( "float", Float.TYPE );
>   typeMap.put( "long", Long.TYPE );
>   typeMap.put( "short", Short.TYPE );
>   typeMap.put( "byte", Byte.TYPE );
>   typeMap.put( "double", Double.TYPE );
>   typeMap.put( "char", Character.TYPE );
> 
>   abbreviationMap.put( "int", "I" );
>   abbreviationMap.put( "boolean", "Z" );
>   abbreviationMap.put( "float", "F" );
>   abbreviationMap.put( "long", "J" );
>   abbreviationMap.put( "short", "S" );
>   abbreviationMap.put( "byte", "B" );
>   abbreviationMap.put( "double", "D" );
>   abbreviationMap.put( "char", "C" );
> }

<snip>

This is similar to my implementation with three important differences:

* the direct usage of types (Integer.TYPE etc.) has obviously problems
in environments with multiple class loaders (eg. Class.forName(String
name, boolean initialize, ClassLoader classLoader); likewise there may
or may not be issues with using static in this context

* int.class is not guaranteed to be equal to Integer.class

* Class.forName is known to be problematic in certain
circumstances/environments; using
Thread.currentThread().getContextClassLoader() might be more useful
(as Henri/Stephen suggested).

I'll add an issue for this in BugZilla with my code attached, and you
guys can decide whether it is useful to include in commons-lang, ok ?

regards,
Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message