Skip to content

Instantly share code, notes, and snippets.

@Falci
Created April 24, 2014 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Falci/11254703 to your computer and use it in GitHub Desktop.
Save Falci/11254703 to your computer and use it in GitHub Desktop.
package me.falci.planoB.javascript;
import java.util.Date;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class Main {
public static void main(String[] args) throws ScriptException {
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
Complex complex = new Complex(123L, "Falci", new Date());
engine.put("complex", complex);
engine.eval("print( complex + '\\n');");
engine.eval("complex.campoLivre = 'Teste';");
engine.eval("print( complex + '\\n');");
engine.eval("print( complex.id + ') '+ complex.nome +' : '+ complex.dob.time )");
}
public static class Complex {
private final Long id;
private final String nome;
private final Date dob;
private String campoLivre;
public Complex(Long id, String nome, Date dob) {
super();
this.id = id;
this.nome = nome;
this.dob = dob;
}
public Long getId() {
return id;
}
public String getNome() {
return nome;
}
public Date getDob() {
return dob;
}
@Override
public String toString() {
return "Complex [id=" + id + ", nome=" + nome + ", dob=" + dob + ", campoLivre=" + campoLivre + "]";
}
public String getCampoLivre() {
return campoLivre;
}
public void setCampoLivre(String campoLivre) {
this.campoLivre = campoLivre;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment