You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * Get all public constructors of the given class. * @param <T> Class type. * @param type Target class * @return All public constructors. */@SuppressWarnings("unchecked")
publicstatic <T> Stream<Constructor<T>> getContructors(finalClass<T> type) {
returnArrays.stream((Constructor<T>[]) type.getConstructors());
}
/** * Find a constructor with the given parameter types. * @param <T> Type of the instance created by the constructor. * @param type Target type * @param args Parameter types. * @return A constructor or empty. */publicstatic <T> Optional<Constructor<T>> findConstructor(finalClass<T> type, finalClass<?>... args) {
returnReflectionUtils.getContructors(type)
.filter(args.length == 0 ? c -> c.getParameterCount() == 0
: c -> ReflectionUtils.isAssignableEach(args, c.getParameterTypes()))
.findAny();
}
/** * Test if the array of type is assignale each other. * @param types1 Type to test. * @param types2 Target type. * @return True if the first array types are assignable to second ones. */publicstaticbooleanisAssignableEach(finalClass<?>[] types1, finalClass<?>[] types2) {
if (types1.length != types2.length) {
returnfalse;
}
for (inti = 0; i < types1.length; i++) {
if (!types1[i].isAssignableFrom(types2[i])) {
returnfalse;
}
}
returntrue;
}
Add a condition to verify primitive types ?
The text was updated successfully, but these errors were encountered:
Add this code below to
ReflectionUtils
:Add a condition to verify primitive types ?
The text was updated successfully, but these errors were encountered: