I have an object defined as follow:
protected Map<String, ? extends List<? extends LightGeometry>> geoms=new HashMap<String,List<LightGeometry>>();
I try to insert in an object that looks conform to the wildcard
ArrayList<LightGeometry> points=new ArrayList<LightGeometry>();
points.add((LightGeometry)new LightPoint(pt));
geoms.put("point", points);
The compiler throws an error that says:
The method
put(String, capture#18-of ? extends List<? extends LightGeometry>
) in the typeMap<String,capture#18-of ? extends List<? extends LightGeometry>>
is not applicable for the arguments(String, ArrayList<LightGeometry>)
What am I missing?
EDIT: Why I am using the wildcard with the generic types
It basically comes down to being able to assign the list (which I get through a service) to a the geoms
object which is in another class, without having to sift through the list to cast.
public void onSuccess(Map<String, ArrayList<LightPolygon>> result) {
// TODO Auto-generated method stub
GWT.log("" + result.size());
Log.debug("" + result.size());
long startTime = System.currentTimeMillis();
if (overlay != null) {
overlay.setData(result);
overlay.update();
Log.debug("time to add features: "
+ (System.currentTimeMillis() - startTime));
}
}
If I were to make the geoms
variable a Map<String, List<LightGeometry>>
then I get a cast error that says that I can't assign a Map<String,ArrayList<LightPolygon>>
to a 'Map>`