From 53c8a548f013490a9fe7a035373e27aa24dcf3d0 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Tue, 17 Dec 2019 06:56:37 +0100 Subject: [PATCH] =?UTF-8?q?[ANY]=20=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D1=88=D0=BE=D0=B9=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=84?= =?UTF-8?q?=D0=B8=D0=B3=D0=B0=D1=85.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launcher/config/SimpleConfig.java | 9 ++++++--- .../pro/gravit/launcher/config/SimpleConfigurable.java | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) 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; } }