I'm really confused right now. I'm using following code in another project without any problems:
public class ReadOnlyTable<T extends Model> implements ReadOnly<T> {
protected at.viswars.database.framework.core.DatabaseTable datasource;
private boolean debug = true;
protected ReadOnlyTable() {
initTable();
}
protected void reloadDataSource() {
initTable();
}
private void initTable() {
boolean readOnlyClass = false;
if (getClass().getSuperclass().equals(ReadOnlyTable.class)) readOnlyClass = true;
Class<T> dataClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
The last line will run without problems. Now i made a second project and as i had problems with reading out the Class i tried to do the most simple case possible:
public class GenericObject<T> implements IGenericObject<T> {
public GenericObject() {
init();
}
private void init() {
Class<T> clazz = (Class<T>)((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
}
This class is instanciated here:
GenericObject<String> go = new GenericObject<String>();
In my second example i will always receive following error message:
Exception in thread "main" java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
What i am missing?? This drives me crazy. Any help is appreciated!