mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[ANY] Небольшой рефакторинг в конфигах.
This commit is contained in:
parent
9cbdd6300c
commit
53c8a548f0
2 changed files with 12 additions and 6 deletions
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launcher.config;
|
package pro.gravit.launcher.config;
|
||||||
|
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.lang.invoke.MethodType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
@ -18,11 +20,12 @@ public T getConfig() {
|
||||||
return (T) this;
|
return (T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
public T getDefaultConfig() {
|
public T getDefaultConfig() {
|
||||||
try {
|
try {
|
||||||
return type.newInstance();
|
return (T) MethodHandles.publicLookup().findConstructor(type, MethodType.methodType(void.class)).invokeWithArguments();
|
||||||
} catch (InstantiationException | IllegalAccessException e) {
|
} catch (Throwable e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.gravit.launcher.config;
|
package pro.gravit.launcher.config;
|
||||||
|
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.lang.invoke.MethodType;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class SimpleConfigurable<T> extends JsonConfigurable<T> {
|
public class SimpleConfigurable<T> extends JsonConfigurable<T> {
|
||||||
|
@ -16,11 +18,12 @@ public T getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
public T getDefaultConfig() {
|
public T getDefaultConfig() {
|
||||||
try {
|
try {
|
||||||
return tClass.newInstance();
|
return (T) MethodHandles.publicLookup().findConstructor(tClass, MethodType.methodType(void.class)).invokeWithArguments();
|
||||||
} catch (InstantiationException | IllegalAccessException e) {
|
} catch (Throwable e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue