How can I access a simple java object as a bean?
For instance:
class Simple {
private String foo;
String getFoo() {
return foo;
}
private void setFoo( String foo ) {
this.foo = foo;
}
}
Now I want to use this object as follows:
Simple simple = new Simple();
simple.setFoo( "hello" );
checkSettings( simple );
So, I am looking for an implementation of a method checkSettings( Object obj ):
public boolean checkSettings( Object obj ) {
Bean bean = new Bean( obj );
if( "hello".equals( bean.getAttribute( "foo" ) ) {
return true;
}
return false;
}
The java language contains a package called java.beansthat sounds like it can help me. But I did not find a good starting point.
Any clues?
source
share