[Bluej-discuss] formatter extension?
Aryeh M. Friedman
aryeh.friedman at gmail.com
Sun Oct 14 07:59:37 BST 2007
I just found a great example of code that would be impossible to
understand without indents from something I am writting on my other
screen currently:
public static Object rebrand(Class brand,Object obj)
throws Throwable
{
ClassLoader loader=ClassLoader.getSystemClassLoader();
Class klass=loader.loadClass(brand.getCanonicalName());
Object real=klass.newInstance();
for(Field f:real.getClass().getDeclaredFields()) {
if(f.getType().isPrimitive())
continue;
Field
oldField=obj.getClass().getDeclaredField(f.getName());
boolean fVis=f.isAccessible();
boolean oVis=oldField.isAccessible();
try {
f.setAccessible(true);
oldField.setAccessible(true);
} catch(Throwable e) {
// if for some reason we can't mod the
accessibility skip it
continue;
}
f.set(real,oldField.get(obj));
f.setAccessible(true);
oldField.setAccessible(true);
}
return real;
}
More information about the bluej-discuss
mailing list