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

Latest commit

 

History

History
57 lines (46 loc) · 1.89 KB

README.md

File metadata and controls

57 lines (46 loc) · 1.89 KB

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