public final class ClassUtils extends Object
Class lookup (locateClass(String, boolean,
ClassLoader)), that allows a full scan (to try all
packages known) and an optional ExternalClassLoader instance that is able to actually compile a .java file on the fly and load its compile
.class file| Constructor and Description |
|---|
ClassUtils() |
| Modifier and Type | Method and Description |
|---|---|
static @Nullable Object |
assignToField(Object o,
String property,
Object value)
Assigns a value to a field
id on the given object o. |
static Set<String> |
collectMethodNames(Class<?> dataType,
boolean publicOnly)
Returns a list of names that represent the methods on an
Object |
static Set<Method> |
collectMethods(Class<?> dataType,
boolean publicOnly)
Returns a list of names that represent the methods on an
Object |
static @NotNull Collection<String> |
collectPropertyNames(Object subject)
Returns a list of names that represent the fields on an
Object. |
static @Nullable Class<?> |
locateClass(String className,
boolean fullscan,
@Nullable ClassLoader classLoader)
Searches the JVM and optionally all of its packages
|
static @Nullable Class<?> |
locateClass(String fullClassName,
@Nullable ClassLoader classLoader)
This function dynamically tries to locate a class.
|
static @Nullable Class<?> |
locateClass(String className,
@Nullable String inPackage,
@Nullable ClassLoader classLoader) |
static <T> T |
newInstanceSimple(Class<T> _class)
Simply calls
Class.newInstance() and hides the exception handling boilerplate code. |
static void |
resetCache() |
static @Nullable Field |
solveField(Object o,
String fieldName)
Returns a field from the given object that goes by the name of
fieldName. |
public static void resetCache()
@Nullable public static @Nullable Class<?> locateClass(String className, boolean fullscan, @Nullable @Nullable ClassLoader classLoader)
className - The name of the class to locate.fullscan - Whether a full scan through all available java packages is required.classLoader - Optional user-provided classloader.Class reference if found or null otherwise.@Nullable public static @Nullable Class<?> locateClass(String className, @Nullable @Nullable String inPackage, @Nullable @Nullable ClassLoader classLoader)
@Nullable public static @Nullable Class<?> locateClass(String fullClassName, @Nullable @Nullable ClassLoader classLoader)
Class.forName(String).fullClassName - The Class that needs to be found.classLoader - Optional user-provided classloader.Class object found from cache or VM.@NotNull public static <T> T newInstanceSimple(Class<T> _class)
Class.newInstance() and hides the exception handling boilerplate code.T - Type used to parameterize the return instance._class - The datatype for which we need to create a new instance of.@Nullable public static @Nullable Field solveField(Object o, String fieldName)
fieldName. If o is a Class object, a static field will
be returned.o - The reference to the object to fetch the property value from.fieldName - The identifier or name of the member field/property.Field.@Nullable public static @Nullable Object assignToField(Object o, String property, Object value) throws IllegalAccessException, NoSuchFieldException
id on the given object o. If a simple assignment fails, a common conversion will be
attempted.o - The object to find the field on.property - The name of the field we're assigning the value to.value - The value to assign to the field, may be converted to the field's type through common conversion.IllegalAccessException - Thrown by Field.set(Object, Object)NoSuchFieldException - Thrown if the Field could not be found, even after trying to convert the value to the target type.ValueConversionHelper.convert(Object, Class)@NotNull public static @NotNull Collection<String> collectPropertyNames(Object subject)
Object.subject - The Object who's properties/fields need to be reflected.Object.public static Set<String> collectMethodNames(Class<?> dataType, boolean publicOnly)
ObjectpublicOnly - Indicates whether only public (albeit inherited) members should be returned. Else also private and protected methods will be
includedMethods.public static Set<Method> collectMethods(Class<?> dataType, boolean publicOnly)
ObjectpublicOnly - Indicates whether only public (albeit inherited) members should be returned. Else also private and protected methods will be
includedMethods.Copyright © 2018. All rights reserved.