You can cast to a Map
and retrieve the key set. If you want, you can also add unbounded generic parameter <?>
to the map and set.
But you are only passing in the class of the data type. You also need to pass in the actual instance. E.g.
mapSomething(someHashMap.getClass(), someHashMap)
And the implementation becomes:
void mapSomething(Class<?> dataType, Object instance)
{
if(dataType.isInstance(Map.class)){
Map<?,?> map = (Map<?,?>)instance;
Set<?> keySet = map.keySet();
}
}
Altenatively, you can just pass the instance, and not the class
void mapSomething(Object instance)
{
if(instance instanceof Map){
Map<?,?> map = (Map<?,?>)instance;
Set<?> keySet = map.keySet();
}
}