Hey, firstly I don't think this is possible. If it isn't, can anyone recommend a better way of doing it?
I have an abstract class with one field that lots of other classes extend, each having different implementations of some abstract methods:
public abstract class Data
private DataType dataType;
public abstract void ...();
DataType is an enum saying what type of data each instance is.
I have a map:
Map<DataType, Set<Data>> allData = new HashMap<DataType, Set<Data>>();
but when i get a value out of the map,
Set<Data> set = allData.get(DataType.X);
I would then have to cast each object inside set
to DataX (if that is what the class is called that corresponds with DataType.X)
for (Data d: set)
DataX dx = (DataX) d; }
But I know
that all the elements inside of set are of type DataX.
Is there any way I can make it so when I get a set out of allData, I can get a set of DataX?
Set<DataX> set = allData.get(DataType.X);