Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7844349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:50:56+00:00 2026-06-02T16:50:56+00:00

I have an object defined as follow: protected Map<String, ? extends List<? extends LightGeometry>>

  • 0

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 type Map<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>`

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:50:57+00:00Added an answer on June 2, 2026 at 4:50 pm

    A generic wildcard does not mean “Anything that extends List” It means “Some specific thing that extends List, but I don’t know what that specific thing is.”

    Therefore it is illegal to add anything to the collection, because you don’t know what the specific thing is! It could be a map of LinkedLists, and here you are putting an ArrayList in it, which would cause someone else to get class cast exception when they assume it’s a LinkedList.

    If you want a Map that holds any type of list, just declare it as a Map of Lists, not a Map of ? extends List.

    —

    tl;dr – it does what you want without the wildcards. Wildcards are usually used for specifying method signatures where it doesn’t matter if you know what the types are. If you just want a collection that holds subclasses, you just specify the supertype.

    example:

    Map<String, List<Number>> map = new HashMap<String,List<Number>>();
    
    List<Number> integers =new ArrayList<Number>();
    integers.add(Integer.valueOf(1));
    map.put("integers", integers);
    
    List<Number> floats = new LinkedList<Number>(); 
    floats.add(Float.valueOf(5.2f));
    map.put("floats", floats);
    

    No casting!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script which creates a user-defined object like this: obj = new
Well, the question is kinda simple. I have a object defined as: public class
I have a static object defined in my logging class, along the lines of:
Suppose I have an entity object defined as public partial class Article { public
I have a serial of object defined as: public class Foo { public DateTime
Say I have a model object 'Person' defined, which has a field called 'Name'.
i have a object in javascript and some already defined functions. but how can
I have defined a global object in a .js file. For example file1.js contains
Suppose I have a user defined type: CREATE OR REPLACE TYPE TEST_TYPE AS OBJECT
I have an Object Factory Class which has a method called registerCreator as defined

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.