MCPcopy Create free account
hub / github.com/e2wugui/zeze / getDefCtor

Method getDefCtor

ZezeJava/ZezeJava/src/main/java/Zeze/Util/Json.java:172–191  ·  view source on GitHub ↗
(@NotNull Class<T> klass)

Source from the content-addressed store, hash-verified

170 }
171
172 @SuppressWarnings("unchecked")
173 public static <T> @NotNull Creator<T> getDefCtor(@NotNull Class<T> klass) {
174 try {
175 for (Constructor<?> c : klass.getDeclaredConstructors()) {
176 if (c.getParameterCount() == 0) {
177 setAccessible(c);
178 MethodHandle ctorMH = lookup.unreflectConstructor(c);
179 return () -> {
180 try {
181 return (T)ctorMH.invoke();
182 } catch (Throwable e) { // MethodHandle.invoke
183 throw new RuntimeException(e);
184 }
185 };
186 }
187 }
188 } catch (IllegalAccessException ignored) {
189 }
190 return () -> (T)unsafe.allocateInstance(klass);
191 }
192
193 private static @Nullable Class<?> getCollectionSubClass(Type geneType) { // X<T>, X extends Y<T>, X implements Y<T>
194 if (geneType instanceof ParameterizedType) {

Callers 3

ClassMetaMethod · 0.95
GTable2Class · 0.80
GTable1Class · 0.80

Calls 2

setAccessibleMethod · 0.80
invokeMethod · 0.65

Tested by

no test coverage detected