public final class ClassUtils extends Object
Constructor and Description |
---|
ClassUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
argsMatch(Class<?>[] paramTypes,
Class<?>[] argTypes)
Returns
|
static boolean |
argsMatch(List<ClassInfo> paramTypes,
Class<?>[] argTypes)
Returns
|
static <T> T |
castOrCreate(Class<T> c,
Object c2)
Creates an instance of the specified class.
|
static <T> T |
castOrCreate(Class<T> c,
Object c2,
boolean fuzzyArgs,
Object... args)
Creates an instance of the specified class.
|
static <T> T |
castOrCreateFromOuter(Object outer,
Class<T> c,
Object c2,
boolean fuzzyArgs,
Object... args)
Creates an instance of the specified class from within the context of another object.
|
static <T> T |
fromString(Class<T> c,
String s)
Constructs a new instance of the specified class from the specified string.
|
static int |
fuzzyArgsMatch(Class<?>[] paramTypes,
Class<?>... argTypes)
Returns a number representing the number of arguments that match the specified parameters.
|
static int |
fuzzyArgsMatch(Class<?>[] paramTypes,
ClassInfo... argTypes)
Returns a number representing the number of arguments that match the specified parameters.
|
static int |
fuzzyArgsMatch(List<ClassInfo> paramTypes,
Class<?>... argTypes)
Returns a number representing the number of arguments that match the specified parameters.
|
static Class<?>[] |
getClasses(Object... args)
Returns the class types for the specified arguments.
|
static ObjectList |
getFullClassNames(Object[] o)
Given the specified list of objects, return readable names for the class types of the objects.
|
static Object[] |
getMatchingArgs(Class<?>[] paramTypes,
Object... args)
Matches arguments to a list of parameter types.
|
static Object[] |
getMatchingArgs(List<ClassInfo> paramTypes,
Object... args)
Matches arguments to a list of parameter types.
|
static boolean |
setAccessible(Constructor<?> x)
Attempts to call
x.setAccessible( and quietly ignores security exceptions. |
static boolean |
setAccessible(Field x)
Attempts to call
x.setAccessible( and quietly ignores security exceptions. |
static boolean |
setAccessible(Method x)
Attempts to call
x.setAccessible( and quietly ignores security exceptions. |
static Class<?> |
toClass(Type t)
Returns the specified type as a
|
static String |
toString(Object o)
Converts an object to a string.
|
public ClassUtils()
public static ObjectList getFullClassNames(Object[] o)
o
- The objects.public static boolean argsMatch(Class<?>[] paramTypes, Class<?>[] argTypes)
paramTypes
- The parameters types specified on a method.argTypes
- The class types of the arguments being passed to the method.public static boolean argsMatch(List<ClassInfo> paramTypes, Class<?>[] argTypes)
paramTypes
- The parameters types specified on a method.argTypes
- The class types of the arguments being passed to the method.public static int fuzzyArgsMatch(Class<?>[] paramTypes, Class<?>... argTypes)
paramTypes
- The parameters types specified on a method.argTypes
- The class types of the arguments being passed to the method.public static int fuzzyArgsMatch(Class<?>[] paramTypes, ClassInfo... argTypes)
paramTypes
- The parameters types specified on a method.argTypes
- The class types of the arguments being passed to the method.public static int fuzzyArgsMatch(List<ClassInfo> paramTypes, Class<?>... argTypes)
paramTypes
- The parameters types specified on a method.argTypes
- The class types of the arguments being passed to the method.public static Class<?>[] getClasses(Object... args)
args
- The objects we're getting the classes of.public static <T> T castOrCreate(Class<T> c, Object c2)
c
- The class to cast to.c2
- The class to instantiate.
Can also be an instance of the class.RuntimeException
- if constructor could not be found or called.public static <T> T castOrCreate(Class<T> c, Object c2, boolean fuzzyArgs, Object... args)
c
- The class to cast to.c2
- The class to instantiate.
Can also be an instance of the class.fuzzyArgs
- Use fuzzy constructor arg matching.
args
- The arguments to pass to the constructor.RuntimeException
- if constructor could not be found or called.public static <T> T castOrCreateFromOuter(Object outer, Class<T> c, Object c2, boolean fuzzyArgs, Object... args)
outer
- The outer object.
Can be c
- The class to cast to.c2
- The class to instantiate.
Can also be an instance of the class.fuzzyArgs
- Use fuzzy constructor arg matching.
args
- The arguments to pass to the constructor.RuntimeException
- if constructor could not be found or called.public static Object[] getMatchingArgs(Class<?>[] paramTypes, Object... args)
Extra parameters are ignored.
Missing parameters are left null.
paramTypes
- The parameter types.args
- The arguments to match to the parameter types.public static Object[] getMatchingArgs(List<ClassInfo> paramTypes, Object... args)
Extra parameters are ignored.
Missing parameters are left null.
paramTypes
- The parameter types.args
- The arguments to match to the parameter types.public static <T> T fromString(Class<T> c, String s)
Class must be one of the following:
c
- The class.s
- The string to create the instance from.public static String toString(Object o)
Normally, this is just going to call Locale
and TimeZone
objects are treated special so that the returned value
works with the fromString(Class, String)
method.
o
- The object to convert to a string.public static boolean setAccessible(Constructor<?> x)
x.setAccessible(true )
and quietly ignores security exceptions.x
- The constructor.public static boolean setAccessible(Method x)
x.setAccessible(true )
and quietly ignores security exceptions.x
- The method.public static boolean setAccessible(Field x)
x.setAccessible(true )
and quietly ignores security exceptions.x
- The field.public static Class<?> toClass(Type t)
If it's already a
If it's a
t
- The type to convert.Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.