A concise and easy-to-use wrapper for the Java Reflection API (java.lang.reflect) that allows for reflection operations in a very non-verbose manner. It also includes a class file manager that allows for you to quickly load and manage Class files from a jar or a directory.
Head over to the releases page. To build, just build with Maven.
import static com.github.silk8192.reflector.Reflector.*;
ClassFileManager cfm = new ClassFileManager(classPath);
//Creation
String str = forClass(String.class).create("Hello, World!").get();
//Calling a method
forClass(String.class).create("Hello, World!").invoke("substring", 3);
//Getting a field
//Person class
String firstName = forClass(cfm.getClass("foo.Person")).create("Foo", "Bar").get("firstName");
//Setting a field
forClass(cfm.getClass("foo.Person")).create("Foo", "Bar").set("firstName", "Bar2");
Using the class file manager:
//For a regular directory
Path classPath = Paths.get("foo\\bar");
ClassFileManager cfm = new ClassFileManager(classPath);
//For a .jar
ClassFileManager cfm = new ClassFileManager(Paths.get("foo\\bar.jar").toFile());
//Accessing files
cfm.getClass("foo.Bar");
- SLF4j Logging
- Commons-io
This project is under the MIT license. See the LICENSE
file for terms.