(@NotNull Class<T> klass)
| 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) { |
no test coverage detected