Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

XDean/ReflectWithoutString

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reflect without String

Build Status codecov.io Maven Central

  • Reflect method and field without String.
  • Get the reflect object from invocation.
  • A type-safe solution of reflection.

Get Start

<dependency>
  <groupId>com.github.XDean</groupId>
  <artifactId>ReflectWithoutString</artifactId>
  <version>2.0.1</version>
</dependency>

If you need use MethodGetter, add following dependency also

<dependency>
  <groupId>cglib</groupId>
  <artifactId>cglib</artifactId>
  <version>3.2.4</version>
</dependency>

Usage

Get Field

	FieldGetter fg = ReflectWithoutString.fieldGetter(SomeClass.class);
	Field field = fg.getField(o -> o.getSomeField());// or s.someField

Get Method

	MethodGetter mg = ReflectWithoutString.methodGetter(SomeClass.class);
	Method method = mg.getMethod(o -> o.someMethod());

Get Property name and type

	PropertyGetter pg = ReflectWithoutString.propertyGetter(SomeClass.class);
	String name = pg.getPropName(o -> o.getSomeField());// name = "someField"
	Class<?> type = pg.getPropType(o -> o.getSomeField());// type = someField's type

Current two implementations compare

Class Base on Construct cost Support field invoke Limit
UnsafeFieldGetter com.misc.Unsafe 0.5s for 1M construct Yes No
ProxyMethodGetter cglib 1s for 1K construct No Final class and method

Also see their javadoc

About

Reflect without String

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages