- Reflect method and field without String.
- Get the reflect object from invocation.
- A type-safe solution of reflection.
<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>
FieldGetter fg = ReflectWithoutString.fieldGetter(SomeClass.class);
Field field = fg.getField(o -> o.getSomeField());// or s.someField
MethodGetter mg = ReflectWithoutString.methodGetter(SomeClass.class);
Method method = mg.getMethod(o -> o.someMethod());
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
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