Java Beans Expression class
public class Person { private String name; public Person() { this("Jane", 23); }/*w ww . jav a2 s .c om*/ public Person(String name, int age) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
import java.beans.Expression; public class Main { public static void main(String args[]) { Person person = new Person(); String arguments[] = { "Peter" }; Expression expression = new Expression(null, person, "setName", arguments); try {// w w w . ja v a 2 s . c om System.out.println("Name: " + person.getName()); expression.execute(); System.out.println("Name: " + person.getName()); System.out.println(); expression = new Expression(null, person, "getName", null); System.out.println("Name: " + person.getName()); expression.execute(); System.out.println("getValue: " + expression.getValue()); } catch (Exception ex) { ex.printStackTrace(); } } }