Reflection
Available since libGDX version 0.9.9. In order to utilize reflection in a cross-platform way, libGDX provides a small wrapper around Java’s reflection api. The wrapper consists mainly of two classes containing the static methods you will use to perform reflection operations:
ArrayReflection- encapsulates access to java.lang.reflect.ArrayClassReflection- encapsulates access to java.lang.Class Other classes included in the wrapper provide access to Constructors, Fields, and Methods. These classes (for the most part) mirror their java.lang.reflect equivalent. and can be used in the same way.Usage
In general, you will use the reflection wrapper the same way you would use Java’s reflection API, except you’d route the calls through the appropriate wrapper class instead of calling the methods directly. Examples:GWT
Because GWT does not allow for reflection in the same way as Java, extra steps are required to make reflection information available to your GWT application. In short, you must specify which classes you plan to use with reflection. When compiling the HTML project, libGDX takes that information and generates a reflection cache containing information about and providing access to the constructors, fields and methods of the specified classes. libGDX then uses this reflection cache to implement the reflection api.*.gwt.xml). To include a single class:
To include an entire package:<extend-configuration-property name="gdx.reflect.include" value="com.me.reflected.ReflectedClass" />
You can also exclude classes of packages (for example when you include a package, but you don’t want all classes or subpackages in that package):<extend-configuration-property name="gdx.reflect.include" value="com.me.reflected" />
Notes<extend-configuration-property name="gdx.reflect.exclude" value="com.me.reflected.NotReflectedClass" />
extend-configuration-propertyelement.CustomActor$CustomActorStyleavailable for reflection (maybe to be used in uiskin.json), just include the parent class (i.e. CustomActor in this example)staticfields cannot be accessed directly viafield.get(Example.class);, instance must be passed in as a parameterfield.get(new Example());
