Class.getField
is your friend. This will probably not be very simple, since Python is dynamically typed, and Java is statically typed (unless you know your field types in advance.)
EDIT: How to translate these examples. http://effbot.org/zone/python-getattr.htm
Attribute Search
Python
//normal value = obj.attribute //runtime value = getattr(obj, "attribute")
Java
//normal value = obj.attribute; //runtime value = obj.getClass().getField("attribute").get(obj);
Method call
Python
//normal result = obj.method(args) //runtime func = getattr(obj, "method") result = func(args)
Java
//normal result = obj.method(args); //runtime Method func = obj.getClass().getMethod("method", Object[].class); result = func.invoke(obj, args);
In simpler cases, you need to know if you have a field or method. esp because they can have the same name. In addition, methods can be overloaded, so you need to know what method signature you want.
If you don't care which method or field you get, you can easily implement this as a helper method.
NPE
source share