NaN:NaN
NaN:NaN
--:-- / --:--
Newgrounds Background Image Theme

Someone gifted atenahh supporter status!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

eval() in Java

630 Views | 7 Replies
New Topic Respond to this Topic

eval() in Java Mar 8, 2009


Hi. I need to evaluate variables in java from a for loop....like this....

for (int i = 1; i <= jobs; i++) { int j = eval("job" + i); }

I know 'eval' isn't the right method. How can I do this in java?


Pods 2010

Response to eval() in Java Mar 8, 2009


I don't think Java supports this.. I might be wrong. You should store the jobs in an array.

for (int i = 0; i < jobs.length; i++) { jobs[i].myMethod(); }

Response to eval() in Java Mar 9, 2009


This is what you get from writing too much actionscript without thinking about how you should design it. Btw, they omitted eval from as 3. (That's your cue to go "NOOOOOOOO!")


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

Response to eval() in Java Mar 9, 2009


At 3/8/09 07:30 PM, matRugDevelopments wrote: Hi. I need to evaluate variables in java from a for loop....like this....

for (int i = 1; i <= jobs; i++)
{
int j = eval("job" + i);
}

I know 'eval' isn't the right method. How can I do this in java?

Since java operates on bytecode, the code needs to be compiled in order to execute, there is no eval statement. Only scripting languages can do eval, because they are interpreted and not compiled.
Afaik, C/C++ and C# are the only languages currently that can do something remotely similar, by executing code at a specified memory area, but that's not "eval" either, as the code in that location needs to be machine code

Besides, never use functions like eval unless its absolutely necessary, which it rarely / never is


"no sound in ass"

Response to eval() in Java Mar 9, 2009


Php is compiled and it got eval, not like I recommend eval.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

Response to eval() in Java Mar 10, 2009


At 3/9/09 02:01 PM, henke37 wrote: Php is compiled and it got eval

PHP is an interpreted language; but yes it does get compiled, but not in the sense an application gets compiled; it gets compiled each time you view a php-page (except if you use optimizers and accelerators) so eval isn't really a big trick there


"no sound in ass"

Response to eval() in Java Mar 11, 2009


AS never had a full 'eval', it only resolved fields in yet another way in order to cause beginners have even less clue to what they're doing. AS3 has stuff like getDefinition and whatnot, but the stupidity of AS2 is gone.

Indeed since bytecode-based runtimes usually don't support runtime evaluation because they only run the bytecode, while for raw interpreters it's a matter of executing the string the same way as the contents of the code file, but it doesn't mean that's impossible to evaluate code in the bytecode runtime. For example there are libraries for Flash to interpret or compile code (the AS3 API allows loading binary data as a Flash file).

Oh and PHP is gay.


BBS Signature

Response to eval() in Java Mar 11, 2009


PHP is pretty much useless for anything besides dynamic web content though.

If the developers would make up their freaking minds, maybe it could be a decent language.