You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Ron Blaschke <ma...@rblasch.org> on 2004/01/20 18:03:32 UTC

Re[4]: new project proposal: Type Conversion Library

Tuesday, January 20, 2004, 2:49:17 PM, you wrote:
SY> I'm still missing the "why" i.e. why do you want this package?  What are
SY> the use-cases?  Technical questions aside, I'd like to know the
SY> motivation for this project ;)

I have a user configuration (kinda like java.util.Properties) that
contains Strings, and a Seconds class whose sole contructor takes a
long.  In my opinion, the Seconds class should not need to know about
(most?) useful conversions, because often you can't. Eg, the only way
I know of to convert a Byte to an Integer is
Byte b = new Byte(10);
...
Integer i = new Integer(b.intValue());

(Should the Integer class have a constructor that takes a Number?)

Another thought that pops up is the conversion of String("3,5,2") to
an int[], or a List that contains Integers.

Maybe, something like
int[] foo = (int[]) TypeConverter.convert("3,5,2".split(","), int[].class);
or
List /* of Integer */ bar = (List) TypeConverter.convert("3,5,2".split(","),
/*container type*/List.class, /*element type*/Integer.class);

Again, such values exist in our (mostly internal) configuration files.

Besides, I'd like to see the constructor-valueOf-asList-toArray stuff cleaned
up a bit by a common interface.

Ron




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