How to convert generic parameter to a class
generics, java
Solution
Without changing the constructor you can't learn anything about `E` at runtime that you didn't already know statically. That's because in Java, there just simply isn't any runtime effect of a generic parameter -- the compiler literally erases all references to `E` in the code it generates. So if you want code that can tell what class its type parameter is being instantiated with, you have to add in some kind of argument (e.g. a `Class` object) yourself. There's just no way around it.
Problem
``` public abstract class BaseDaoImpl<E extends AbstractEntity> implements BaseDao<E> { ..... public BaseDaoImpl() throws DataAccessException { logger = LoggerFactory.getLogger(E); <<-- error here. } ``` In the above code I get a error in the call to `getLogger(E)`. E cannot be resolved to a variable This makes sense, but `getLogger(E.class)` (or variants thereof) does not work either. I don't want to pass the literal class in the constructor, so a solution like changing the the constructor header to: `public BaseDaoImpl(Class<E> clazz) ...` is not an option. How do I get the class type from `E`? Note that the answers to: How to get class of generic type when there is no parameter of it? do not help.