I am using reflection to put all my class\'s member variables that are of type Card
class into an ArrayList
instance. How do I finish t
Field
is just the description of the field, it is not the value contained in there.
You need to first get the value, and then you can cast it:
Card x = (Card) field.get(this);
Also, you probably want to allow subclasses as well, so you should do
// if (field.getType() == Card.class) {
if (Card.class.isAssignableFrom(field.getType()) {