The Jolliest Java Reflection Library on the 7 Seas.
Java reflection is often a treacherous journey filled with sharks and scallywags. Let R help you navigate your way through Davy Jones Locker.
Before leaving on your adventure, be sure to pack R aboard your ship:
// We are on Maven Central
dependencies {
implementation "me.mrnavastar:r:1.0.8"
}
Now that were off, you need to wrap the object you want to plunder (reflect):
import me.mrnavastar.r.R;
R reflector = R.of(myPoorObject);
// You can also chain .of() calls on fields inside the object you just wrapped:
R reflector = R.of(myPoorObject).of("somePoorField");
With our treasure secured, it's time to show those landlubbers a real buccaneer:
// To get the value from a field (can be a private or a parent class field)
reflector.get("someField", Type.class);
// To set the value of a field (can be a private, final, or parent class field)
reflector.set("someField", myValue);
// To call a function (can be a private or a parent class function)
reflector.call("myFunction", ReturnType.class, param1, param2 ...);
// Get type params
reflector.generics();
Now that you've got your sea legs and are rolling in doubloons, be sure to loot with caution. Remember... dead men tell no tales.