Type the Class<T> factory that replaces new T()
Type the Class<T> factory that replaces new T()
Answer
static <T> T create(Class<T> type) throws Exception { return type.getDeclaredConstructor().newInstance(); }
Because new T() is impossible under erasure, you pass the Class<T> token. It survives erasure as an ordinary object, so newInstance() has the runtime type that the bare type parameter lacks. This is the standard workaround.