public final class ReflectionUtils extends Object
Do not remove this header!
Version 1.0
MIT License
Copyright (c) 2016
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| Modifier and Type | Method and Description |
|---|---|
static <T extends Annotation> |
invokeAnnotationByClass(Class<?> clazz,
Class<T> annotationClazz)
Invokes the annotation of the given clazz
|
static <T extends Annotation> |
invokeAnnotationByField(Field field,
Class<T> annotationClazz)
Invokes the annotation of the given field
|
static <T extends Annotation> |
invokeAnnotationByMethod(Method method,
Class<T> annotationClazz)
Invokes the annotation of the given method
|
static Class<?> |
invokeClass(String name)
Returns the class from the name and converts VERSION to the current server version.
|
static Object |
invokeConstructor(Class<?> clazz,
Class<?>[] paramTypes,
Object[] params)
Creates a new instance of the given clazz, paramTypes, params
|
static <T> T |
invokeDefaultConstructor(Class<T> clazz)
Creates a new instance of the given clazz with the default constructor
|
static <T> T |
invokeFieldByClass(Class<?> clazz,
String name)
Invokes the field of the given class and name
|
static <T> T |
invokeFieldByObject(Object instance,
String name)
Invokes the field of the given instance and name
|
static <T> T |
invokeFieldByObject(Object instance,
String name,
Class<?> clazz)
Invokes the field of the given instance and name
|
static <T> T |
invokeMethodByClass(Class<?> clazz,
String name,
Class<?>[] paramTypes,
Object[] params)
Invokes the static method of the given clazz, name, paramTypes, params
|
static <T> T |
invokeMethodByObject(Object instance,
String name,
Class<?>[] paramTypes,
Object[] params)
Invokes the method of the given instance, name, paramTypes, params
|
static <T> T |
invokeMethodByObject(Object instance,
String name,
Class<?>[] paramTypes,
Object[] params,
Class<?> clazz)
Invokes the method of the given instance, name, paramTypes, params
|
public static Class<?> invokeClass(String name) throws ClassNotFoundException
name - nameClassNotFoundException - exceptionpublic static <T> T invokeDefaultConstructor(Class<T> clazz) throws IllegalAccessException, InstantiationException
T - returnTypeclazz - clazzIllegalAccessException - exceptionInstantiationException - exceptionInstancepublic static Object invokeConstructor(Class<?> clazz, Class<?>[] paramTypes, Object[] params) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException
clazz - clazzparamTypes - paramTypesparams - paramsIllegalAccessException - exceptionInvocationTargetException - exceptionInstantiationException - exceptionNoSuchMethodException - exceptionpublic static <T> T invokeMethodByClass(Class<?> clazz, String name, Class<?>[] paramTypes, Object[] params) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
T - returnTypeclazz - clazzname - nameparamTypes - paramTypesparams - paramsNoSuchMethodException - exceptionInvocationTargetException - exceptionIllegalAccessException - exceptionpublic static <T> T invokeMethodByObject(Object instance, String name, Class<?>[] paramTypes, Object[] params) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
T - returnTypeinstance - instancename - nameparamTypes - paramTypesparams - paramsNoSuchMethodException - exceptionInvocationTargetException - exceptionIllegalAccessException - exceptionpublic static <T> T invokeMethodByObject(Object instance, String name, Class<?>[] paramTypes, Object[] params, Class<?> clazz) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
T - returnTypeinstance - instancename - nameparamTypes - paramTypesparams - paramsclazz - clazzNoSuchMethodException - exceptionInvocationTargetException - exceptionIllegalAccessException - exceptionpublic static <T> T invokeFieldByClass(Class<?> clazz, String name) throws NoSuchFieldException, IllegalAccessException
T - returnTypeclazz - clazzname - nameNoSuchFieldException - exceptionIllegalAccessException - exceptionpublic static <T> T invokeFieldByObject(Object instance, String name) throws NoSuchFieldException, IllegalAccessException
T - returnTypeinstance - instancename - nameNoSuchFieldException - exceptionIllegalAccessException - exceptionInstancepublic static <T> T invokeFieldByObject(Object instance, String name, Class<?> clazz) throws NoSuchFieldException, IllegalAccessException
T - returnTypeinstance - instancename - nameclazz - clazzNoSuchFieldException - exceptionIllegalAccessException - exceptionInstancepublic static <T extends Annotation> T invokeAnnotationByClass(Class<?> clazz, Class<T> annotationClazz)
T - returnTypeclazz - clazzannotationClazz - annotationpublic static <T extends Annotation> T invokeAnnotationByField(Field field, Class<T> annotationClazz)
T - returnTypefield - fieldannotationClazz - annotationpublic static <T extends Annotation> T invokeAnnotationByMethod(Method method, Class<T> annotationClazz)
T - returnTypemethod - methodannotationClazz - annotationCopyright © 2017. All rights reserved.