総称型を取得するのに便利
example
package jp.mirageworld.dao;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Map;
import org.seasar.framework.util.tiger.GenericUtil;
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class AbstractDao<E> {
protected final Class<E> entityClass;
@SuppressWarnings("unchecked")
public AbstractDao() {
Class<E> entityClass = null;
Map<TypeVariable<?>, Type> map;
map = GenericUtil.getTypeVariableMap(getClass());
for (Class<?> c = getClass(); c != Object.class; c = c.getSuperclass()) {
if (c.getSuperclass() == AbstractDao.class) {
Type type = c.getGenericSuperclass();
Type[] arrays = GenericUtil.getGenericParameters(type);
entityClass = (Class<E>) GenericUtil.getActualClass(arrays[0], map);
break;
}
}
this.entityClass = entityClass;
}
}