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

  • Home
  • SEARCH
  • 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 8631839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:16:20+00:00 2026-06-12T09:16:20+00:00

I asked a similiar question 10 minutes ago, but pasted the wrong code snippet.

  • 0

I asked a similiar question 10 minutes ago, but pasted the wrong code snippet. I’m really sorry about that.

I’m currently facing an issue with base and subclasses.

While having a single object as parameter (method single) the compiler doesn’t complain.

But if it comes to lists the compiler forces me to declare the list as <? extends Base>

After that I’m no longer allowed to add objects of the base type to that list.

The error message: “The method list(List<Generics.Base>) in the type Generics.C is not applicable for the arguments (List<Generics.Sub>)”

public class Generics {

    class Base {    }

    class Sub extends Base{     }

    interface I {
        public void list( List<Base> list );
        public void single( Base list );
    }

    class C implements I {
        public void list( List<Base> b) {       }
        public void single( Base p) {       }
    }

    void test() {
        C c = new C();
        c.single( new Sub() );
        List<Sub> b = new ArrayList<Sub>(); 
        c.list( b );                    // error message as above
    }

    public static void main( String[] args) {
        Generics g = new Generics();
        g.test();
    }
}

Is there any other way but declaring the list-methods argument as type <? extends Base> ?

  • 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-12T09:16:21+00:00Added an answer on June 12, 2026 at 9:16 am

    Below are the 2 ways to do it….

    public void list(List<? extends Base> list){
    
    }
    

    Or

    public <T extends Base> void list(List<T> list){
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked a similar question yesterday but I included some code that basically took
I asked a similar question about this previously, but I did not specify that
Note: I've asked this question in a similiar format on superuser but it seems
Somebody asked similar question not long ago. But nobody answered comprehensively. Assume I have:
I asked a similar question in Code Review forum but was suggested to ask
I asked a similar question a while ago Error Creating Debug Information - Code
I asked a similar question yesterday, but recognize that i need to rephase it
Note : I asked a similar question 5 minutes ago, however this is not
I asked a similar question a couple of days ago, but I'm looking for
I asked a similar question previously, but it was so vague that I couldn't

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.