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();  }
@Test @SuppressWarnings("unchecked") public void shouldCreateBaseClassInstanceEvenWithSubclassNewInstance() throws NoSuchMethodException { final NonConstructableGenericBaseClass<Long> instance = NonConstructableGenericBaseClass.newInstance(NonConstructableGenericBaseClass.class, Long.class, 5); assertThat(valueOf(instance.getFieldA()), is(5)); assertTrue(instance.getMemberClass() == Long.class); }
@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); }