mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
25d69f38ee
An inner class has two sets of modifier flags: one is declared in the usual place in the class file and the other is part of the InnerClasses attribute. Not only is that redundant, but they can contradict, and the VM can't just pick one and roll with it. Instead, Class.getModifiers must return the InnerClasses version, whereas reflection must check the top-level version. So even if Class.getModifiers says the class is protected, it might still be public for the purpose of reflection depending on what the InnerClasses attribute says. Crazy? Yes.
10 lines
189 B
Java
10 lines
189 B
Java
package avian;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
public class TestReflection {
|
|
public static Object get(Field field, Object target) throws Exception {
|
|
return field.get(target);
|
|
}
|
|
}
|