Executing a string related to source code, not the command line

A

Arun

How can i execute a string, for example:

int x = 2;
int y = 4;
int z;
String command = " z = x*y "


For some background on why i want to do this:


I have an element tree.
To add a certain element, i need to use the following command:
element.getChild("bla").setContent(newElement);

Problem is that the number of .getChild() corresponds to the element
depth in the tree.
So if its depth was two, then the command would be:
element.getChild("bla's dad").getChild("bla").setContent(newElement);

I can't do a for loop and then with every iteration get the child from
the previous child, because when i add an element i won't be adding it
to the whole element tree, il just be adding it to the previous
element.

I could build the whole tree again but that seems wasteful.
 
A

Arun

Let me rephrase the third paragraph:

I cant do a for loop because when i add an element, i will only be
adding it to its parent (which now will exist as its own element).
Instead i want to add the element to the whole tree.
 
M

Michael Borgwardt

Arun said:
Let me rephrase the third paragraph:

I cant do a for loop because when i add an element, i will only be
adding it to its parent (which now will exist as its own element).
Instead i want to add the element to the whole tree.

I'm not sure what you mean with "add the element to the whole tree",
but whatever you want to do with that tree, you DON'T need to
compile any java code on the fly for it! Loops and recursion (or stacks)
can do anything that can be done with a tree.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top