Tuesday, August 19, 2008

Reflection, the complicated way .. :-)

Just found that in some code, had to share this gem:

Object o = ...;
 
try {
bsh.Interpreter i = new bsh.Interpreter();
i.set("foo",o);
String bar = i.eval("foo.bar");
}
catch (bsh.EvalError e) {
...
}


Ok, not everyone is intimate with reflection and Interpreters often don't care what exact runtime type an object is (as long as you they are assignment compatible), but the effort to call BSH for this is as high as to write some reflection code for it :-) Also pulling in BSH mean for that piece of code to quadruple the binary size ...

No comments:

Post a Comment