I have an interface to convert object to string:
public interface Converter {
String asString(T object);
}
And a map to store
You are facing issue called wildcard capture.
Java is unable to identify the type that will be received from the List> data.
Try refactoring your code in any of the two ways
Method 1: Change your interface as below
interface Converter {
String asString(Object object);
}
Method 2: Helper method to capture wild card by type inference
Create an helper method as below,
// Helper method created so that the wildcard can be captured
// through type inference.
private void helper(List data) {
Map, Converter> converterMap = null;
List stringData = null;
for (T datum : data) {
stringData.add(converterMap.get(datum.getClass()).asString(datum));
}
}
Call this helper method as below
List> data = fetchData();
helper(data);