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 7852099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:20:24+00:00 2026-06-02T19:20:24+00:00

Here is my problem: my function in class A: public void setData(Map<String,? extends ArrayList<?

  • 0

Here is my problem:
my function in class A:

public void setData(Map<String,? extends ArrayList<? extends SomeInterface>>){...}

my call:

Map<String, ArrayList<ImplementsSomeInterface>> a=...;
instanceOfA.setData(a); //does not compile
instanceOfA.setData((Map<String,? extends ArrayList<? extends SomeInterface>>) a); // works thanks to the Casting.

I don’t think this is clean. Is there a way to avoid the casting without droping the wildcard use in the function?

  • 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-02T19:20:25+00:00Added an answer on June 2, 2026 at 7:20 pm

    First your setData method should read:

    public void setData(Map<String,? extends List<? extends SomeInterface>>)
    

    Your map declaration should read:

    Map<String, List<ImplementsSomeInterface>> a = ...;
    

    Which is pretty much what you’ve got following your edits to the original question. The change I’ve made from ArrayList to List doesn’t effect the behaviour of the code.

    Following comments:

    public static void main() 
    {
        Map<String, List<Double>> map = new HashMap<String, List<Double>>();
        map.put("prices", new ArrayList<Double>(Arrays.asList(1.1, 2.2, 3.3)));
    
        setData(map);
    }
    
    public static void setData(Map<String,? extends List<? extends Serializable>> map)      
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the problem i am facing, does anyone have solution? Class A: public
I am using thread to start a public function of a class. The problem
Here is my problem. I made a class with a member function declared as
Maddening problem here. When my page loads: <body onload=getClientDateTime();> It runs this function: document.getElementById('ClientDateTime').value=hello
I have a problem with using a pointer to function in C++. Here is
I' having a problem allocating a structure in a function. Here is the code(I'm
Trying to truncate some code here and running into a problem: <script type=text/javascript> $(function()
I'm having a problem with scala generics. While the first function I defined here
date here my problem: String datetime = 2012-03-24 23:20:51; I know that that string
UPDATE:: OK i am putting the original problem statement here Given the Main class

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.