Is it at all possible to cast a generic class's type to a given Class object in java? Something like this:
public ModelBin<?> getModelBin(Class type) {
return (ModelBin<type>) entities.get(type);
}
The compiler tells me that it can't resolve type to a type. I know I could just do this,
public ModelBin<?> getModelBin(Class type) {
return entities.get(type);
}
and it would work but then I would have to cast each model out of the model bin later on in the program - which is more work.
I did some more reading and ended up with this:
public <T> ModelBin<T> getModelBin(Class<T> type) {
return (ModelBin<T>) entities.get(type);
}
Would this have the funciton return a ModelBin<type> object?
HashMap<Class, ModelBin<?>>Class<?>instead of the rawClass.