@Test public void configurationLoaderShouldInitializeClass() { TestConfig config = configurationLoader.initClass(); assertNotNull(config); assertNull(config.name); }
@Nullable protected T initClass() { T instance = null; try { final Constructor<T> constructor = getClazz().getDeclaredConstructor(); constructor.setAccessible(true); instance = constructor.newInstance(); } catch (NoSuchMethodException e) { getLogger().log(Level.SEVERE, e, () -> "Couldn't find the default constructor for the class " + clazz.getSimpleName()); } catch (IllegalAccessException | InstantiationException e) { getLogger().log(Level.SEVERE, e, () -> "Failed to initialize the class " + clazz.getSimpleName()); } catch (InvocationTargetException e) { getLogger().log(Level.SEVERE, e.getCause(), () -> "An exception was thrown when trying to initialize the class " + clazz.getSimpleName()); } return instance; }
ConfigurationLoader { @Nullable protected T initClass() { T instance = null; try { final Constructor<T> constructor = getClazz().getDeclaredConstructor(); constructor.setAccessible(true); instance = constructor.newInstance(); } catch (NoSuchMethodException e) { getLogger().log(Level.SEVERE, e, () -> "Couldn't find the default constructor for the class " + clazz.getSimpleName()); } catch (IllegalAccessException | InstantiationException e) { getLogger().log(Level.SEVERE, e, () -> "Failed to initialize the class " + clazz.getSimpleName()); } catch (InvocationTargetException e) { getLogger().log(Level.SEVERE, e.getCause(), () -> "An exception was thrown when trying to initialize the class " + clazz.getSimpleName()); } return instance; } }
ConfigurationLoader { @Nullable protected T initClass() { T instance = null; try { final Constructor<T> constructor = getClazz().getDeclaredConstructor(); constructor.setAccessible(true); instance = constructor.newInstance(); } catch (NoSuchMethodException e) { getLogger().log(Level.SEVERE, e, () -> "Couldn't find the default constructor for the class " + clazz.getSimpleName()); } catch (IllegalAccessException | InstantiationException e) { getLogger().log(Level.SEVERE, e, () -> "Failed to initialize the class " + clazz.getSimpleName()); } catch (InvocationTargetException e) { getLogger().log(Level.SEVERE, e.getCause(), () -> "An exception was thrown when trying to initialize the class " + clazz.getSimpleName()); } return instance; } protected  ConfigurationLoader(@NotNull C config, Runnable saveConfig, @NotNull Class<T> clazz); }
ConfigurationLoader { @Nullable protected T initClass() { T instance = null; try { final Constructor<T> constructor = getClazz().getDeclaredConstructor(); constructor.setAccessible(true); instance = constructor.newInstance(); } catch (NoSuchMethodException e) { getLogger().log(Level.SEVERE, e, () -> "Couldn't find the default constructor for the class " + clazz.getSimpleName()); } catch (IllegalAccessException | InstantiationException e) { getLogger().log(Level.SEVERE, e, () -> "Failed to initialize the class " + clazz.getSimpleName()); } catch (InvocationTargetException e) { getLogger().log(Level.SEVERE, e.getCause(), () -> "An exception was thrown when trying to initialize the class " + clazz.getSimpleName()); } return instance; } protected  ConfigurationLoader(@NotNull C config, Runnable saveConfig, @NotNull Class<T> clazz); void save(@NotNull Object instance); T load(); abstract Object getConfigValue(AnnotatedField field, @Nullable Object defaultValue); abstract void setConfigValue(AnnotatedField field, @Nullable Object value); abstract void registerTypeAdapter(TypeAdapter<?> typeAdapter); Logger getLogger(); C getConfig(); Runnable getSaveConfig(); Class<T> getClazz(); }
ConfigurationLoader { @Nullable protected T initClass() { T instance = null; try { final Constructor<T> constructor = getClazz().getDeclaredConstructor(); constructor.setAccessible(true); instance = constructor.newInstance(); } catch (NoSuchMethodException e) { getLogger().log(Level.SEVERE, e, () -> "Couldn't find the default constructor for the class " + clazz.getSimpleName()); } catch (IllegalAccessException | InstantiationException e) { getLogger().log(Level.SEVERE, e, () -> "Failed to initialize the class " + clazz.getSimpleName()); } catch (InvocationTargetException e) { getLogger().log(Level.SEVERE, e.getCause(), () -> "An exception was thrown when trying to initialize the class " + clazz.getSimpleName()); } return instance; } protected  ConfigurationLoader(@NotNull C config, Runnable saveConfig, @NotNull Class<T> clazz); void save(@NotNull Object instance); T load(); abstract Object getConfigValue(AnnotatedField field, @Nullable Object defaultValue); abstract void setConfigValue(AnnotatedField field, @Nullable Object value); abstract void registerTypeAdapter(TypeAdapter<?> typeAdapter); Logger getLogger(); C getConfig(); Runnable getSaveConfig(); Class<T> getClazz();  }