Created
April 24, 2014 13:32
-
-
Save Falci/11254703 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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