Search code examples
javareflectionfunctionjava-mehecl

How to declare a function during program execution?


This is something like Reflection where you can call a method simply by its name, and not a precompiled pointer to it.

Like in JavaScript you can:

var fun = function(){    alert("Hello World!");    }
fun();

Is something like that possible in Java/J2ME? How?


Solution

  • If you want an interpreter for j2me, you could check out Hecl: http://www.hecl.org

    You definitely can't do most of the 'fancy' things you can do in normal Java in J2ME. The alternative is a series of if/elseif's that then call the function you want, but you still have to know that ahead of time so that you can write the code that does that.