Java reflection: get internal field of an instance
I have an interface that looks like this:
public interface A {
public interface B {
public static final Cat cat = new Cat("Alice");
}
}
Is there a way to access the Cat object through reflection?
I've tried this:
Field catField = Class.forName("A.B").getField("cat");
But this gives me a ClassNotFoundException.
Thanks in advance!
+3
source to share