In a Spring 3 webapp, I have a DAO that looks something like this:
public class BaseDAOImpl<T extends AbstractEntity> implements BaseDAO<T> {
...
public void doSomething(Class<T> clazz) {
log.debug("class name: " + clazz.getName());
...
}
...
}
That log prints what I'm looking for, let's say com.xyz.Customer.
But that logging line above is just for illustration. In the app, I'm using an aspect to handle logging. And in that aspect, I'm recording arguments. So in my @Before
advice, I have some code like this:
...
Object[] args = joinPoint.getArgs();
for (Object o : args) {
...
log.debug("class name: " + o.getClass().getName());
...
And when that runs against clazz
in BaseDAOImlp's doSomething()
, it logs as java.lang.Class.
So, while understanding that generics are implemented via type erasure, I don't understand why I see com.xyz.Customer with the getName()
call in doSomething()
, but java.lang.Class in the aspect.