diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java index 507376d0..1dd9d94f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java @@ -1,5 +1,7 @@ package pro.gravit.launcher.config; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.lang.reflect.Type; import java.nio.file.Path; @@ -18,11 +20,12 @@ public T getConfig() { return (T) this; } - @Override + @SuppressWarnings("unchecked") + @Override public T getDefaultConfig() { try { - return type.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + return (T) MethodHandles.publicLookup().findConstructor(type, MethodType.methodType(void.class)).invokeWithArguments(); + } catch (Throwable e) { return null; } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java index 5027e9eb..347dabd9 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java @@ -1,5 +1,7 @@ package pro.gravit.launcher.config; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.nio.file.Path; public class SimpleConfigurable extends JsonConfigurable { @@ -16,11 +18,12 @@ public T getConfig() { return config; } - @Override + @SuppressWarnings("unchecked") + @Override public T getDefaultConfig() { try { - return tClass.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + return (T) MethodHandles.publicLookup().findConstructor(tClass, MethodType.methodType(void.class)).invokeWithArguments(); + } catch (Throwable e) { return null; } }