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:
1 2 3 4 5 6
| 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:
1
| Map<DataType, Set<Data>> allData = new HashMap<DataType, Set<Data>>(); |
but when i get a value out of the map,
1
| 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)
1 2 3 4 5
| 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?
1
| Set<DataX> set = allData.get(DataType.X); |
Thanks,
roland