Object or Class upon which reflective calls
can be made.
An example of using Reflect is
// Static import all reflection methods to decrease verbosity
import static org.joor.Reflect.*;
// Wrap an Object / Class / class name with the on() method:
on("java.lang.String")
// Invoke constructors using the create() method:
.create("Hello World")
// Invoke methods using the call() method:
.call("toString")
// Retrieve the wrapped object
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final Constructor | |
| private final Object | object
The wrapped object. |
| private final Class | type
The type of the wrapped object. |
| Access | Constructor and Description |
|---|---|
| private | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static <T extends AccessibleObject> T | Returns: The argument object rendered accessibleThe object to render accessible accessible)Conveniently render an |
| public <P> P | |
| public <P> P | Returns: A proxy for the wrapped objectThe interface type that is implemented by the proxy proxyType, final Class<?>... Additional interfaces that are implemented by
the proxy additionalInterfaces)Create a proxy for the wrapped object allowing to typesafely invoke methods on it using a custom interface. |
| public Reflect | |
| public Reflect | |
| public static Reflect | |
| public static Reflect | Returns: A wrappedClassThe qualified class name name, String The source code for the class content, CompileOptions compiler options options)Compile a class at runtime and reflect on it. |
| public Reflect | |
| public Reflect | |
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. |
| private Method | exactMethod(String name, Class<?>[] types)
Searches a method with the exact same signature as desired. |
| public Reflect | |
| private Field | |
| public Map | Returns: A map containing field names and wrapped values.Get a Map containing field names and wrapped values for the fields' values. |
| private static Class | |
| private static Class | |
| public < A convenience generic parameter for automatic unsafe casting T> T | |
| public <T> T | |
| public int | |
| public static <T> T | |
| private boolean | isSimilarSignature(Method possiblyMatchingMethod, String desiredMethodName, Class<?>[] desiredParamTypes)
Determines if a method has a "similar" signature, especially if wrapping primitive argument types would result in an exactly matching signature. |
| private boolean | |
| public static Reflect | Returns: A wrapped class object, to be used for further reflection.A fully qualified class name name)
Deprecated
[#78] 0.9.11, use
Wrap a class name.
onClass(String) instead.
|
| public static Reflect | Returns: A wrapped class object, to be used for further reflection.A fully qualified class name. name, ClassLoader The class loader in whose context the class should be
loaded. classLoader)
Deprecated
[#78] 0.9.11, use
Wrap a class name, loading it via a given class loader.
onClass(String, ClassLoader) instead.
|
| public static Reflect | Returns: A wrapped class object, to be used for further reflection.The class to be wrapped clazz)
Deprecated
[#78] 0.9.11, use
Wrap a class.
onClass(Class) instead.
|
| public static Reflect | |
| private static Reflect | |
| private static Reflect | |
| private static Reflect | |
| public static Reflect | |
| public static Reflect | Returns: A wrapped class object, to be used for further reflection.A fully qualified class name. name, ClassLoader The class loader in whose context the class should be
loaded. classLoader)Wrap a class name, loading it via a given class loader. |
| public static Reflect | |
| private static String | |
| public Reflect | |
| private Method | similarMethod(String name, Class<?>[] types)
Searches a method with a similar signature as desired using
|
| public String | |
| public Class | |
| private static Class | |
| private static Object | |
| public static <T> Class |
| CACHED_LOOKUP_CONSTRUCTOR | back to summary |
|---|---|
| pack-priv static final Constructor<MethodHandles. | |
| object | back to summary |
|---|---|
| private final Object object The wrapped object. | |
| type | back to summary |
|---|---|
| private final Class<?> type The type of the wrapped object. | |
| Reflect | back to summary |
|---|---|
| private Reflect(Class<?> type) | |
| Reflect | back to summary |
|---|---|
| private Reflect(Class<?> type, Object object) | |
| accessible | back to summary |
|---|---|
| public static <T extends AccessibleObject> T accessible(T accessible) Conveniently render an
To prevent
| |
| as | back to summary |
|---|---|
| public <P> P as(Class<P> proxyType) Create a proxy for the wrapped object allowing to typesafely invoke methods on it using a custom interface.
| |
| as | back to summary |
|---|---|
| public <P> P as(final Class<P> proxyType, final Class<?>... additionalInterfaces) Create a proxy for the wrapped object allowing to typesafely invoke methods on it using a custom interface.
| |
| call | back to summary |
|---|---|
| public Reflect call(String name) throws ReflectException Call a method by its name.
This is a convenience method for calling
| |
| call | back to summary |
|---|---|
| public Reflect call(String name, Object... args) throws ReflectException Call a method by its name.
This is roughly equivalent to
Just like The first of the following methods will be called:
The best matching method is searched for with the following strategy:
| |
| compile | back to summary |
|---|---|
| public static Reflect compile(String name, String content) throws ReflectException Compile a class at runtime and reflect on it. For example:
| |
| compile | back to summary |
|---|---|
| public static Reflect compile(String name, String content, CompileOptions options) throws ReflectException Compile a class at runtime and reflect on it. For example:
| |
| create | back to summary |
|---|---|
| public Reflect create() throws ReflectException Call a constructor.
This is a convenience method for calling
| |
| create | back to summary |
|---|---|
| public Reflect create(Object... args) throws ReflectException Call a constructor.
This is roughly equivalent to
Just like The first of the following constructors will be applied:
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| exactMethod | back to summary |
|---|---|
| private Method exactMethod(String name, Class<?>[] types) throws NoSuchMethodException Searches a method with the exact same signature as desired.
If a public method is found in the class hierarchy, this method is returned.
Otherwise a private method with the exact same signature is returned.
If no exact match could be found, we let the | |
| field | back to summary |
|---|---|
| public Reflect field(String name) throws ReflectException Get a wrapped field.
This is roughly equivalent to
| |
| field0 | back to summary |
|---|---|
| private Field field0(String name) throws ReflectException | |
| fields | back to summary |
|---|---|
| public Map Get a Map containing field names and wrapped values for the fields' values.
If the wrapped object is a These two calls are equivalent
| |
| forName | back to summary |
|---|---|
| private static Class Load a class
| |
| forName | back to summary |
|---|---|
| private static Class | |
| get | back to summary |
|---|---|
| public <T> T get() Get the wrapped object
| |
| get | back to summary |
|---|---|
| public <T> T get(String name) throws ReflectException Get a field value.
This is roughly equivalent to
If you want to "navigate" to a wrapped version of the field, use
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| initValue | back to summary |
|---|---|
| public static <T> T initValue(Class<T> type) Get the initialisation or default value for any given type. This returns:
| |
| isSimilarSignature | back to summary |
|---|---|
| private boolean isSimilarSignature(Method possiblyMatchingMethod, String desiredMethodName, Class<?>[] desiredParamTypes) Determines if a method has a "similar" signature, especially if wrapping primitive argument types would result in an exactly matching signature. | |
| match | back to summary |
|---|---|
| private boolean match(Class<?>[] declaredTypes, Class<?>[] actualTypes) Check whether two arrays of types match, converting primitive types to their corresponding wrappers. | |
| on | back to summary |
|---|---|
| public static Reflect on(String name) throws ReflectException
Deprecated [#78] 0.9.11, use Wrap a class name.
This is the same as calling
| |
| on | back to summary |
|---|---|
| public static Reflect on(String name, ClassLoader classLoader) throws ReflectException
Deprecated [#78] 0.9.11, use Wrap a class name, loading it via a given class loader.
This is the same as calling
| |
| on | back to summary |
|---|---|
| public static Reflect on(Class<?> clazz)
Deprecated [#78] 0.9.11, use Wrap a class.
Use this when you want to access static fields and methods on a
| |
| on | back to summary |
|---|---|
| public static Reflect on(Object object) Wrap an object.
Use this when you want to access instance fields and methods on any
| |
| on | back to summary |
|---|---|
| private static Reflect on(Class<?> type, Object object) | |
| on | back to summary |
|---|---|
| private static Reflect on(Constructor<?> constructor, Object... args) throws ReflectException Wrap an object created from a constructor | |
| on | back to summary |
|---|---|
| private static Reflect on(Method method, Object object, Object... args) throws ReflectException Wrap an object returned from a method | |
| onClass | back to summary |
|---|---|
| public static Reflect onClass(String name) throws ReflectException Wrap a class name.
This is the same as calling
| |
| onClass | back to summary |
|---|---|
| public static Reflect onClass(String name, ClassLoader classLoader) throws ReflectException Wrap a class name, loading it via a given class loader.
This is the same as calling
| |
| onClass | back to summary |
|---|---|
| public static Reflect onClass(Class<?> clazz) Wrap a class.
Use this when you want to access static fields and methods on a
| |
| property | back to summary |
|---|---|
| private static String property(String string) Get the POJO property name of an getter/setter | |
| set | back to summary |
|---|---|
| public Reflect set(String name, Object value) throws ReflectException Set a field value.
This is roughly equivalent to
This method is also capable of setting the value of (static) final
fields. This may be convenient in situations where no
For restrictions of usage regarding setting values on final fields check: http://stackoverflow.com/questions/3301635/change-private-static-final-field-using-java-reflection ... and http://pveentjer.blogspot.co.at/2017/01/final-static-boolean-jit.html
| |
| similarMethod | back to summary |
|---|---|
| private Method similarMethod(String name, Class<?>[] types) throws NoSuchMethodException Searches a method with a similar signature as desired using
First public methods are searched in the class hierarchy, then private
methods on the declaring class. If a method could be found, it is
returned, otherwise a | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| type | back to summary |
|---|---|
| public Class Get the type of the wrapped object.
| |
| types | back to summary |
|---|---|
| private static Class Get an array of types for an array of objects
| |
| unwrap | back to summary |
|---|---|
| private static Object unwrap(Object object) Unwrap an object | |
| wrapper | back to summary |
|---|---|
| public static <T> Class Get a wrapper type for a primitive type, or the argument type itself, if it is not a primitive type.
| |
| Access | Constructor and Description |
|---|---|
| private |
| NULL | back to summary |
|---|---|
| private NULL() | |