
/* package whatever; // don't place package name! */

import java.lang.reflect.ParameterizedType;

/* Name of the class has to be "Main" only if the class is public. */
abstract class BaseDao<T> {

	@SuppressWarnings("unchecked")
	protected Class<T> getClazz() {

		final ParameterizedType type = (ParameterizedType) this.getClass()
				.getGenericSuperclass();
		Class<T> clazz = (Class<T>) type.getActualTypeArguments()[0];
		return clazz;
	}

	public static void main(String[] args) throws java.lang.Exception {

		BaseDao<String> daoString = new BaseDao<String>() {};
		System.out.println(daoString.getClazz().getSimpleName());
		BaseDao<Long> daoLong = new BaseDao<Long>() {};
		System.out.println(daoLong.getClazz().getSimpleName());
	}

}
