 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
None Guest
|
Posted: Fri Jun 02, 2006 3:10 am Post subject: Dynamic array creation |
|
|
Dynamic array creation
Hi all... here's a good one for you...
I have a situation where I have some bean, and I need to populate an
array field in it... here's the problem... I do not know the element
type of the array before runtime.
Now, I've been planning on using Commons Beanutils, since the rest of
this particular app does (it's doing a lot of introspection of the
beans and such).
So, here's the question... can anyone figure out a way to dynamically
create an array at runtime? What I mean is, I want to do the
followig:
PropertyUtils.setProperty(obj, fieldName,
((List)fieldValues).toArray());
So, I want to set the field named by fieldName on the bean instance
referenced by obj, and I want to do it by taking the fieldValues List
and converting it to an array. Now, I can do:
PropertyUtils.setProperty(obj, fieldName,
((List)fieldValues).toArray(new String[0]));
....and that's great, except that I don't know until runtime that the
field of the bean is of type String, it could be anything else. So,
how can I dynamically do the equivalent of the new String[0] is really
the question?
FYI, I don't really care if this is done with Beanutils, but I think
that's probably the logical course of action. Any ideas? Thanks all! |
|
| Back to top |
|
 |
Oliver Wong Guest
|
Posted: Fri Jun 02, 2006 3:10 pm Post subject: Re: Dynamic array creation |
|
|
"None" <none (AT) none (DOT) com> wrote in message
news:qa7v72trjgdijmi4c6l17aeir82n28f6u8 (AT) 4ax (DOT) com...
| Quote: | Dynamic array creation
|
Multipost, don't crosspost:
http://www.cs.tut.fi/~jkorpela/usenet/xpost.html |
|
| Back to top |
|
 |
CV Guest
|
Posted: Fri Jun 16, 2006 5:22 pm Post subject: Re: Dynamic array creation |
|
|
None wrote:
| Quote: | Dynamic array creation
Hi all... here's a good one for you...
I have a situation where I have some bean, and I need to populate an
array field in it... here's the problem... I do not know the element
type of the array before runtime.
|
Can't you use a class from the Collection framework instead of an array?
An ArrayList object for example.
C |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|