JavaBean enhancements in Java 7 - Java Object Oriented Design

Java examples for Object Oriented Design:Java Bean

Description

JavaBean enhancements in Java 7

Demo Code

import java.beans.Expression;
class Person {//w  ww .ja  va2 s. c o  m
    private String name;

    public Person() {
        this("Jane", 23);
    }

    public Person(String name, int age) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }  
}
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 {
            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();
        }
    }
    
}

Related Tutorials