/** * Instantiates class by given type, while it reflects annotation {@link ImplementedBy} in order to determine final * implementation of given type. * * @param type the type of the instantiated instance, which can be either final implementation type or type annotated by * {@link ImplementedBy} in order to determine final implementation of given type. * @return instance of given type */ public static <T> T instantiate(Class<T> type) { try { Class<? extends T> resolvedType = resolveType(type); return SecurityActions.newInstance(resolvedType.getName(), new Class<?>[] {}, new Object[] {}, type); } catch (Exception e) { throw new IllegalStateException(String.format("Cannot instantiate an instance of class '%s': %s", type.getName(), e.getMessage()), e); } }
/** * Instantiates class by given type, while it reflects annotation {@link ImplementedBy} in order to determine final * implementation of given type. * * @param type the type of the instantiated instance, which can be either final implementation type or type annotated by * {@link ImplementedBy} in order to determine final implementation of given type. * @return instance of given type */ public static <T> T instantiate(Class<T> type) { try { Class<? extends T> resolvedType = resolveType(type); return SecurityActions.newInstance(resolvedType.getName(), new Class<?>[] {}, new Object[] {}, type); } catch (Exception e) { throw new IllegalStateException(String.format("Cannot instantiate an instance of class '%s': %s", type.getName(), e.getMessage()), e); } }