T
Taria
Hello all,
Is it possible for Java to generate names within a program and create
an object from that new name? For example, let's say we are given a
set of data to work from and I have a class named NodeInfo which has
information pertaining to this set of data. The number of nodes that
can be generated will depend on the number of elements in the set of
data and can possibly turn into thousands of nodes. (Unlikely in this
school assignment but I'm trying to create something efficient.)
For now, I am tackling this problem like this. When i generate a
child node (which I want to have NodeInfo's class structure), I will
refer to them in order of creation as "node1, node2, node3..etc. So
essentially, in pseudocode:
generate new node name
NodeInfo (newNodeName here) = new NodeInfo();
<data manipulation after this>
Is this possible and if so, what is it called? I have tried to look
online and have found dynamic class loading (I'm pretty sure I'm not
doing that) and various pages that give me info about things I'm also
pretty sure has nothing to do with what I want to do.
An alternative way I've thought of was to create a kind of surrogate
key where I'd create an index of my own associated with the value of
the node within an array structure. I'm at a loss how I would
retreive each node's info though right now. Or maybe even create 5
different arrays and have them referenced in parallel, where I know
that the index of 1 would refer to the first node across the 5
arrays. I tried that earlier but it was very messy.
Anyway, any thoughts on whether using a newly created name as an
object is possible or anything is appreciated (as always.)
-t (the very weary)
Is it possible for Java to generate names within a program and create
an object from that new name? For example, let's say we are given a
set of data to work from and I have a class named NodeInfo which has
information pertaining to this set of data. The number of nodes that
can be generated will depend on the number of elements in the set of
data and can possibly turn into thousands of nodes. (Unlikely in this
school assignment but I'm trying to create something efficient.)
For now, I am tackling this problem like this. When i generate a
child node (which I want to have NodeInfo's class structure), I will
refer to them in order of creation as "node1, node2, node3..etc. So
essentially, in pseudocode:
generate new node name
NodeInfo (newNodeName here) = new NodeInfo();
<data manipulation after this>
Is this possible and if so, what is it called? I have tried to look
online and have found dynamic class loading (I'm pretty sure I'm not
doing that) and various pages that give me info about things I'm also
pretty sure has nothing to do with what I want to do.
An alternative way I've thought of was to create a kind of surrogate
key where I'd create an index of my own associated with the value of
the node within an array structure. I'm at a loss how I would
retreive each node's info though right now. Or maybe even create 5
different arrays and have them referenced in parallel, where I know
that the index of 1 would refer to the first node across the 5
arrays. I tried that earlier but it was very messy.
Anyway, any thoughts on whether using a newly created name as an
object is possible or anything is appreciated (as always.)
-t (the very weary)