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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:27:04+00:00 2026-05-13T17:27:04+00:00

I thought I understood this but obviously not… I have a method signature like

  • 0

I thought I understood this but obviously not…

I have a method signature like so:

void doSomething(List<TypeA> typeAs){...}

List<TypeA<TypeB>> getTypeBTypeAs(){...}

but if I try and call

doSomething(getTypeBTypeAs());

I get a compile error: “the method doSomething(List) in the type … is not applicable for the arguments (List>)”

however if i change the sig of doSomething to

void doSomething(List<TypeA<?>> typeAs){...}

it still doesn’t work, but

void doSomething(List typeAs){...}

obviously it works as i bypass generics.

which seems odd.

Can someone fill me in?

Also, in this case I’d like doSomething to work with any List containing TypeAs of any generic type; undefined, TypeB, TypeC etc.

thanks.

  • 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-05-13T17:27:04+00:00Added an answer on May 13, 2026 at 5:27 pm

    A generic class TypeA<TypeB> is a different type from TypeA. You can’t pass in a parameter of type TypeA<TypeB> where the method expects a TypeA. Also TypeA<TypeB> is a different type from TypeA<TypeC>, so the same constraints apply.

    The classic example (from Effective Java, 2nd Ed. AFAIR) is: we have containers for animals (Container<Animal>) and as subclasses of Animal we have Lion and Butterfly. Now, if you have a method

    void func(Animal animal);
    

    it will accept both lions and butterflies. However, this function

    void func(Container<Animal> animalContainer);
    

    will not accept a Container<Lion>, neither a Container<Butterfly>. Do realize that a strong cage useful for keeping lions safely would not stop butterflies from flying away, and vice versa a thick but light net to hold butterflies would not stand a chance against a lion.

    If you really are sure that any kind of animal container suits you, declare your function like this:

    void func(Container<? extends Animal> animalContainer);
    

    Back to your case, I guess the only method to accept both List<TypeA> and List<TypeA<TypeB>> would be something like this:

    void doSomething(List<?> list);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought I understood sed but I guess not. I have the following two
Initially I thought this was going to work, but now I understand it won't
I really thought I understood Python variable referencing, so I'm confused why this code
After I thought that I've understood how they work, I tried this: NSString *str1
I don't claim to know anything about svn, but I thought I understood how
Not sure how to work this but I found a way that works although
I have a question regarding compiling against SDK's, which I thought I understood until
I have a mysql query that I thought should be using my indexes but
You have this code in Javascript (even though language choice does not matter): var
Being a newbie I thought I understood what to do from a security standpoint

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.