- private <T> T getField(Object obj, String field)
- {
- try {
- Class cls = obj.getClass();
- Field f = cls.getField(field);
- return (T)f.get(obj);
- }
- catch(NoSuchFieldException x) {
- Log.v("AllegroSurface", "field " + field + " not found in class " + obj.getClass().getCanonicalName());
- return null;
- }
- catch(IllegalArgumentException x) {
- Log.v("AllegroSurface", "this shouldn't be possible, but fetching " + field + " from class " + obj.getClass().getCanonicalName() + " failed with an illegal argument exception");
- return null;
- }
- catch(IllegalAccessException x) {
- Log.v("AllegroSurface", "field " + field + " is not accessible in class " + obj.getClass().getCanonicalName());
- return null;
- }
- }
-
- private <T> T callMethod(Object obj, String methName, Class [] types, Object... args)
- {
- try {
- Class cls = obj.getClass();
- Method m = cls.getMethod(methName, types);
- return (T)m.invoke(obj, args);
- }
- catch(NoSuchMethodException x) {
- Log.v("AllegroSurface", "method " + methName + " does not exist in class " + obj.getClass().getCanonicalName());