jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Juozas Baliuka" <bali...@centras.lt>
Subject Re: [OT - sort of] Primitives hurt!
Date Sat, 18 Jan 2003 18:21:02 GMT

paste code from this page, it handles arrays too:
http://cglib.sourceforge.net/xref/net/sf/cglib/ReflectUtils.html#124

> I'm stuck at an issue that maybe someone on the list can help
>
>
> The nice thing about the Type class is that I can hand it a "Class"
> object and get back the appropriate type.
>
> public static getType(Class cls)...
>
> I need to keep generic-ness in my application (which is a small BCEL
> taglibrary for Jelly to manipulate Beans). This means I have something
like
>
> *
> <bcel:property name="foo" type="java.lang.String" ...>
> *
>
> so I'm passing around String representations of Classes to methods like
>
> *
> public void addProperty(String name, String type,...){
>
> Type propType = Type.getType(Class.forName(type));
> ...
> *
>
> which works great for regular Classes, unfortunately it doesn't work for
>   primitive types. Calls like:
>
> *
> Class.forName("int")
> *
>
> just don't work, which is frustrating because for the reciprical case:
>
> *
> java.lang.Object.class.toString() returns "java.lang.Object"
> java.lang.Object.getClass().getName() returns "java.lang.Object"
> Class.forName("java.lang.Object").toString() returns "java.lang.Object"
> *
>
> while
>
> *
> int.class.toString() returns "int"
> int.getClass().getName() returns "int"
> *
>
> but
>
> *
> Class.forName("int").toString()
> *
>
> fails with a ClassNotFoundException.
>
> This is something that sucks about primitive type names in the Java API.
> My question, is there a simple way in BCEL to get around this issue, I
> could require the type parameter of my method to require a signature,
> but that is hard for users (who don't know what they are) to use my
> tools, I'd rather be able to just capture the Class object for any
> String representation of a primitive type ("int", "double", "byte" ...)
> and do it simply and elegantly.
>
> Thanks for any comments,
> Mark
>
>
> --
> To unsubscribe, e-mail:
<mailto:bcel-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:bcel-user-help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <mailto:bcel-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:bcel-user-help@jakarta.apache.org>


Mime
View raw message