How to build a function on the fly in java?

Posted by stereos on Stack Overflow See other posts from Stack Overflow or by stereos
Published on 2010-03-29T00:29:27Z Indexed on 2010/03/29 0:33 UTC
Read the original article Hit count: 306

Filed under:

I'm parsing a text file that is being mapped to some java code like such:

public void eval(Node arg)
    {
        if(arg.data.equals("rand"))
        {
            moveRandomly();
        }
        else if(arg.data.equals("home"))
        {
            goHome();
        }//snip..

This is going to need to be re-evaluated about a thousand times and I'd rather not have to traverse the whole thing every time. Is there any way to make this traversal once and then have it be a function that is called every other time?

© Stack Overflow or respective owner

Related posts about java