public final class ReflectionExtensions extends Object
ReflectionExtensions.| Constructor and Description |
|---|
ReflectionExtensions() |
| Modifier and Type | Method and Description |
|---|---|
static <T> void |
copyFieldValue(T source,
T target,
String fieldName)
Copies the field value of the given source object to the given target object.
|
static String |
firstCharacterToUpperCase(String fieldName)
Sets the first character from the given string to upper case and returns it.
|
static Field[] |
getAllDeclaredFields(@NonNull Class<?> cls)
Gets all the declared fields which means from all superclasses from the given class object
|
static Field |
getDeclaredField(Class<?> cls,
String fieldName)
Gets the
Field that match to the given field name that exists in the given class. |
static <T> Field |
getDeclaredField(T object,
String fieldName)
Gets the
Field that match to the given field name that exists in the given object. |
static List<String> |
getFieldNames(Class<?> cls)
Gets all field names from the given class as an String list.
|
static <T> Object |
getFieldValue(T source,
String fieldName)
Gets the field value of the given source object over the field name.
|
static String[] |
getMethodNames(Class<?> cls)
Gets all method names from the given class as an String array.
|
static Map<String,String> |
getMethodNamesWithPrefixFromFieldNames(List<String> fieldNames,
String prefix)
Generates a Map with the fieldName as key and the method as value.
|
static List<String> |
getModifiers(Field field)
Gets the modifiers from the given Field as a list of String objects.
|
static <T> T |
newInstance(Class<T> clazz)
Creates a new instance from the same type as the given Class.
|
static <T> T |
newInstance(T object)
Creates a new instance from the same type as the given object.
|
static <T> void |
setFieldValue(Class<?> cls,
String fieldName,
Object newValue)
Sets the field value of the given class object over the field name.
|
static <T> void |
setFieldValue(T source,
String fieldName,
Object newValue)
Sets the field value of the given source object over the field name.
|
public static <T> void copyFieldValue(T source,
T target,
String fieldName)
throws NoSuchFieldException,
SecurityException,
IllegalAccessException
T - the generic type of the objectsource - the sourcetarget - the targetfieldName - the field nameNoSuchFieldException - is thrown if no such field exists.SecurityException - is thrown if a security manager says no.IllegalAccessException - is thrown if an illegal on create an instance or access a method.public static <T> void setFieldValue(T source,
String fieldName,
Object newValue)
throws NoSuchFieldException,
SecurityException,
IllegalAccessException
T - the generic typesource - the sourcefieldName - the field namenewValue - the new valueNoSuchFieldException - is thrown if no such field exists.SecurityException - is thrown if a security manager says no.IllegalAccessException - is thrown if an illegal on create an instance or access a method.public static <T> Object getFieldValue(T source, String fieldName) throws NoSuchFieldException, SecurityException, IllegalAccessException
T - the generic typesource - the sourcefieldName - the field nameNoSuchFieldException - is thrown if no such field exists.SecurityException - is thrown if a security manager says no.IllegalAccessException - is thrown if an illegal on create an instance or access a method.public static <T> void setFieldValue(Class<?> cls, String fieldName, Object newValue) throws NoSuchFieldException, SecurityException, IllegalAccessException
T - the generic typecls - The classfieldName - the field namenewValue - the new valueNoSuchFieldException - is thrown if no such field exists.SecurityException - is thrown if a security manager says no.IllegalAccessException - is thrown if an illegal on create an instance or access a method.public static List<String> getFieldNames(Class<?> cls)
cls - The class object to get the field names.public static String[] getMethodNames(Class<?> cls)
cls - The class object to get the method names.public static Map<String,String> getMethodNamesWithPrefixFromFieldNames(List<String> fieldNames, String prefix)
fieldNames - A list with the field names.prefix - The prefix for the method name.public static String firstCharacterToUpperCase(String fieldName)
fieldName - The String to modify.public static List<String> getModifiers(Field field)
field - The field to get the modifiers.public static <T> T newInstance(T object)
throws InstantiationException,
IllegalAccessException,
ClassNotFoundException
T - the generic typeobject - the objectClassNotFoundException - is thrown if the class cannot be locatedIllegalAccessException - is thrown if the class or its default constructor is not accessible.InstantiationException - is thrown if this Class represents an abstract class, an interface, an
array class, a primitive type, or void; or if the class has no default
constructor; or if the instantiation fails for some other reason.public static <T> T newInstance(Class<T> clazz) throws InstantiationException, IllegalAccessException
T - the generic typeclazz - the Class objectIllegalAccessException - is thrown if the class or its default constructor is not accessible.InstantiationException - is thrown if this Class represents an abstract class, an interface, an
array class, a primitive type, or void; or if the class has no default
constructor; or if the instantiation fails for some other reason.public static <T> Field getDeclaredField(@NonNull T object, String fieldName) throws NoSuchFieldException, SecurityException
Field that match to the given field name that exists in the given object.T - the generic typeobject - the objectfieldName - the field nameNoSuchFieldException - is thrown if no such field exists.SecurityException - is thrown if a security manager says no.public static Field getDeclaredField(Class<?> cls, String fieldName) throws NoSuchFieldException, SecurityException
Field that match to the given field name that exists in the given class.cls - the class objectfieldName - the field nameNoSuchFieldException - is thrown if no such field exists.SecurityException - is thrown if a security manager says no.Copyright © 2015–2018 Alpha Ro Group UG (haftungsbeschrÀngt). All rights reserved.