I have a utility method and when irrelevant logic is removed from it, the simplified method would look like this:
public static List<
Something more generic:
public static T createInstance(final Class clazz) throws SecurityException, NoSuchMethodException,
IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
T instanceToReturn = null;
Class< ? > enclosingClass = clazz.getEnclosingClass();
if (enclosingClass != null) {
Object instanceOfEnclosingClass = createInstance(enclosingClass);
Constructor ctor = clazz.getConstructor(enclosingClass);
if (ctor != null) {
instanceToReturn = ctor.newInstance(instanceOfEnclosingClass);
}
} else {
instanceToReturn = clazz.newInstance();
}
return instanceToReturn;
}