What could cause java.lang.reflect.InvocationTargetException?

Well, I’ve tried to understand and read what could cause it but I just can’t get it: I have this somewhere in my code: try{ .. m.invoke(testObject); .. } catch(AssertionError e){ … } catch(Exception e){ .. } Thing is that, when it tries to invoke some method it throws InvocationTargetException instead of some other expected … Read more

Why does C++ not have reflection?

This is a somewhat bizarre question. My objectives are to understand the language design decision and to identify the possibilities of reflection in C++. Why C++ language committee did not go towards implementing reflection in the language? Is reflection too difficult in a language that does not run on a virtual machine (like java)? If … Read more

How do I use reflection to invoke a private method?

There are a group of private methods in my class, and I need to call one dynamically based on an input value. Both the invoking code and the target methods are in the same instance. The code looks like this: MethodInfo dynMethod = this.GetType().GetMethod(“Draw_” + itemType); dynMethod.Invoke(this, new object[] { methodParams }); In this case, … Read more

How do I check if a type is a subtype OR the type of an object?

To check if a type is a subclass of another type in C#, it’s easy: typeof (SubClass).IsSubclassOf(typeof (BaseClass)); // returns true However, this will fail: typeof (BaseClass).IsSubclassOf(typeof (BaseClass)); // returns false Is there any way to check whether a type is either a subclass OR of the base class itself, without using an OR operator … Read more

How can I get a list of all classes within current module in Python?

I’ve seen plenty of examples of people extracting all of the classes from a module, usually something like: # foo.py class Foo: pass # test.py import inspect import foo for name, obj in inspect.getmembers(foo): if inspect.isclass(obj): print obj Awesome. But I can’t find out how to get all of the classes from the current module. … Read more

Get class name of object as string in Swift

Getting the classname of an object as String using: object_getClassName(myViewController) returns something like this: _TtC5AppName22CalendarViewController I am looking for the pure version: “CalendarViewController”. How do I get a cleaned up string of the class name instead? I found some attempts of questions about this but not an actual answer. Is it not possible at all? … Read more