mardi 18 août 2015

access field of type Class inside a class

I have a class called myClass and it looks like this:

public class myClass{
Class x;
Class y;
}

I am trying to create another variable called classX which will represent "x" from myClass. I have looked at this question: retrieve field of type class

and done the following:

Class<?> classX = (Class<?>) c.getDeclaredField("x").get(c);

Where c refers to myClass.class wrapped around Object, and cast to Class. However, I keep getting this exception being thrown:

java.lang.IllegalArgumentException: Can not set java.lang.Class field myClass.x to java.lang.Class





Aucun commentaire:

Enregistrer un commentaire