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?
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?
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();
}
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!")
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
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
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.
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.