Retrieving the inherited attribute names/values using Java Reflection

no, you need to write it yourself. It is a simple recursive method called on Class.getSuperClass(): public static List<Field> getAllFields(List<Field> fields, Class<?> type) { fields.addAll(Arrays.asList(type.getDeclaredFields())); if (type.getSuperclass() != null) { getAllFields(fields, type.getSuperclass()); } return fields; } @Test public void getLinkedListFields() { System.out.println(getAllFields(new LinkedList<Field>(), LinkedList.class)); }

Objective-C Introspection/Reflection

UPDATE: Anyone looking to do this kind of stuff might want to check out Mike Ash’s ObjC wrapper for the Objective-C runtime. This is more or less how you’d go about it: #import <objc/runtime.h> . . . -(void)dumpInfo { Class clazz = [self class]; u_int count; Ivar* ivars = class_copyIvarList(clazz, &count); NSMutableArray* ivarArray = [NSMutableArray … Read more

Finding what methods a Python object has

For many objects, you can use this code, replacing ‘object’ with the object you’re interested in: object_methods = [method_name for method_name in dir(object) if callable(getattr(object, method_name))] I discovered it at diveintopython.net (now archived), that should provide some further details! If you get an AttributeError, you can use this instead: getattr() is intolerant of pandas style … Read more

Get an object properties list in Objective-C

I just managed to get the answer myself. By using the Obj-C Runtime Library, I had access to the properties the way I wanted: – (void)myMethod { unsigned int outCount, i; objc_property_t *properties = class_copyPropertyList([self class], &outCount); for(i = 0; i < outCount; i++) { objc_property_t property = properties[i]; const char *propName = property_getName(property); if(propName) … Read more

How can you print a variable name in python? [duplicate]

If you insist, here is some horrible inspect-based solution. import inspect, re def varname(p): for line in inspect.getframeinfo(inspect.currentframe().f_back)[3]: m = re.search(r’\bvarname\s*\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)’, line) if m: return m.group(1) if __name__ == ‘__main__’: spam = 42 print varname(spam) I hope it will inspire you to reevaluate the problem you have and look for another approach.