@Test public void shouldCreateBaseClassInstance() throws NoSuchMethodException { final NonConstructableGenericBaseClass<Long> instance = NonConstructableGenericBaseClass.newInstance(Long.class, 5); assertThat(valueOf(instance.getFieldA()), is(5)); assertTrue(instance.getMemberClass() == Long.class); }
@SuppressWarnings("unchecked") public static <T> NonConstructableGenericSubClass<T> newInstance(Class<T> memberClass, int argA) throws NoSuchMethodException { return (NonConstructableGenericSubClass<T>) NonConstructableGenericBaseClass.newInstance(NonConstructableGenericSubClass.class, memberClass, argA); }
NonConstructableGenericSubClass extends NonConstructableGenericBaseClass<T> { @SuppressWarnings("unchecked") public static <T> NonConstructableGenericSubClass<T> newInstance(Class<T> memberClass, int argA) throws NoSuchMethodException { return (NonConstructableGenericSubClass<T>) NonConstructableGenericBaseClass.newInstance(NonConstructableGenericSubClass.class, memberClass, argA); } }
NonConstructableGenericSubClass extends NonConstructableGenericBaseClass<T> { @SuppressWarnings("unchecked") public static <T> NonConstructableGenericSubClass<T> newInstance(Class<T> memberClass, int argA) throws NoSuchMethodException { return (NonConstructableGenericSubClass<T>) NonConstructableGenericBaseClass.newInstance(NonConstructableGenericSubClass.class, memberClass, argA); } NonConstructableGenericSubClass(Class<T> memberClass, int argA, int argB, int argC);  NonConstructableGenericSubClass(Class<T> memberClass, int argA); }
NonConstructableGenericSubClass extends NonConstructableGenericBaseClass<T> { @SuppressWarnings("unchecked") public static <T> NonConstructableGenericSubClass<T> newInstance(Class<T> memberClass, int argA) throws NoSuchMethodException { return (NonConstructableGenericSubClass<T>) NonConstructableGenericBaseClass.newInstance(NonConstructableGenericSubClass.class, memberClass, argA); } NonConstructableGenericSubClass(Class<T> memberClass, int argA, int argB, int argC);  NonConstructableGenericSubClass(Class<T> memberClass, int argA); @SuppressWarnings("unchecked") static NonConstructableGenericSubClass<T> newInstance(Class<T> memberClass, int argA); @SuppressWarnings("unchecked") static NonConstructableGenericSubClass<T> newInstance(Class<T> memberClass, int argA, int argB, int argC); int getFieldB(); int getFieldC(); }
NonConstructableGenericSubClass extends NonConstructableGenericBaseClass<T> { @SuppressWarnings("unchecked") public static <T> NonConstructableGenericSubClass<T> newInstance(Class<T> memberClass, int argA) throws NoSuchMethodException { return (NonConstructableGenericSubClass<T>) NonConstructableGenericBaseClass.newInstance(NonConstructableGenericSubClass.class, memberClass, argA); } NonConstructableGenericSubClass(Class<T> memberClass, int argA, int argB, int argC);  NonConstructableGenericSubClass(Class<T> memberClass, int argA); @SuppressWarnings("unchecked") static NonConstructableGenericSubClass<T> newInstance(Class<T> memberClass, int argA); @SuppressWarnings("unchecked") static NonConstructableGenericSubClass<T> newInstance(Class<T> memberClass, int argA, int argB, int argC); int getFieldB(); int getFieldC();  }