ReflectUtil
ReflectUtil
provides some nice reflection utilities:
isInstanceOf(Object, Class)
is dynamic version of instanceof
, much faster then Class.isInstance()
.
isSublcass(Class, Class)
determines if one class is sublass of other.
getMethod0(Object, String, Class[])
works as getMethod()
without throwing an exception.
newInstance(Class)
recognizes wrappers and instantiate them with default values (since they do not have empty constructors). It also recognizes Map
, List
, Set
and arrays.
getAccessibleMethods
is a little gem. It returns all methods of a class, including of superclasses, that are accessible from the given class. This means, for example, that all private methods in the given class are visible, but not private methods from the superclasses, and so on. Returned methods are those that user would be able to use from given class. Overloaded methods are not duplicated and the top one is selected.
getAccessibleFields
works the same, but for fields.
getSupportedMethods
returns all methods from class, including of superclasses. Methods are not duplicated.
And so on...