Project Nashorn, javascript + java?

Posted on

Question :

I found the approach interesting after studying deeper education bytecode InvokeDynamic . But I have doubts about the design and practical use.

Will the javac natively understand the javascript block and will it generate the bytecode from that mixed code?

I would like to understand the advantages / disadvantages of using javascript embedded in java applications. If possible some code snippet and a practical demonstration of that usage.


Answer :

After some research, I came to some conclusions regarding my question, they were:

Regarding an example of in java + javascript encoding I could find in a reference a #

Following I worked on a different, more advanced example, mixing java and javascript:

public class NashornEval {
public static void main(String... args) {

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("nashorn");

String js;
js = "var Thread = java.lang.Thread; n";
js += "var map = n";
js += "var names = ["corinthians"", ""palmeiras"", ""santos""]n""

Leave a Reply

Your email address will not be published. Required fields are marked *