Inject anonymous classes with spring
问题 I've read a lot about getting generic type at runtime and I've understood that to prevent full type erasure and get generic type without giving it to constructor I can use an anonymous class plus an utility method, i.e. interface Generic<T> { public Class<T> getGenericType(); } @Component class GenericImpl<T> extends AbstractGenericImpl<T> { } abstract class AbstractGenericImpl<T> implements Generic<T> { protected Class<T> klass; @SuppressWarnings("unchecked") public Class<T> getGenericType()