Java reflection "blindly" getting values
I am trying to get values from classes by reflection.
The thing is开发者_运维百科 that I don't always know what Type to cast the value.
Is there a way of knowing?
field.getType()
Cast it to java.lang.Object IMO
You could get the type of the value that is returned, which might be usefull if you might have different types of values assigned to let's say a field that has an interface/superclass type.
Additionally, you might want to look into java.beans.Introspector which would return field descriptors along with the getters and setters. Note that this only works if the introspected class complies with the Java Beans conventions.
加载中,请稍侯......
精彩评论