Skip to content

alxkm/reflector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reflector Reflector

Build Status License: MIT

Reflector is small and simple reflection Java library.

Library main usage is:

  • get class methods private or not
  • get class fields
  • select annotated fields
  • select and clear some fields
  • invoke new instance of class
  • invoke object method
  • read object field
  • read object field as map
  • other (get class name, package, super)
  • get method
  • get declard methods
  • get default interfaces methods

Required java version is java 8

Specially not used java 8 features to keep more obvious code. And formatting also not according to official java code style for such reason.

Quick start

Usage example:

Get all private fields:

List<Field> fields = ReflectionUtils.getAllPrivateFields(List.class);

Get all public and protected methods:

List<Method> allPublicProtectedMethods = ReflectionUtils.getAllPublicProtectedMethods(List.class);

Get all private methods from java.util.List:

List<Method> allPublicProtectedMethods = ReflectionUtils.getAllPrivateMethods(List.class);

Get all annotated fields with @Autowired annotation:

List<Field> fields = ReflectionUtils.getAllAnnotatedFields(DataService.class, Autowired.class);

Get all annotated fields:

String fullClassNameWithPackage = "org.data.model.User";

Object[] obj = {"Name", "Surname"};

User instance = (User) ReflectionUtils.invokeInstance(fullClassNameWithPackage, obj);

Get method by name:

ReflectionUtil.findMethod(Person.class, "getId")

Get declared methods by class:

List<Method> methods = ReflectionUtil.getDeclaredMethodsList(Person.class)

Get declared methods by class:

Method[] methods = ReflectionUtil.getDeclaredMethods(Person.class)

Get declared methods by class:

List<Method> methods = ReflectionUtil.findDefaultMethodsOnInterfaces(Person.class)

Changelog

0.0.1:

  • initial release

Releases

No releases published

Packages

No packages published

Languages