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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:09:42+00:00 2026-05-28T04:09:42+00:00

I have a class FourByFourBoard that extends GameBoard . I define the following fields:

  • 0

I have a class FourByFourBoard that extends GameBoard. I define the following fields:

private Map<Integer,List<Key<? extends GameBoard>>> mGameTypeToKeysMap = new Hashtable<Integer,List<Key<? extends GameBoard>>>();

private List<Key<FourByFourBoard>> mFourByFourBoardKeys = new ArrayList<Key<FourByFourBoard>>();

In my constructor, I try to call:

mGameTypeToKeysMap.put(Game.FOUR_BY_FOUR, mFourByFourBoardKeys);

But I get this:

The method put(Integer, List<Key<? extends GameBoard>>) in the type
Map<Integer,List<Key<? extends GameBoard>>> is not applicable for the
arguments (int, List<Key<FourByFourBoard>>)

I can use a different approach to do what I’m trying to do, but after staring at the code for a little while I can’t quite figure out why this doesn’t work.

EDIT

This problem might be simpler than I thought:

If I try:

Key<GameBoard> a = mFourByFourBoardKeys.get(0);

I get:

Type mismatch: cannot convert from Key<FourByFourBoard> to
Key<GameBoard>

Even though:

GameBoard someBoard = new FourByFourBoard();

Is legal. So this is still a generics question, but the collections part was not important. And my head is still spinning a little.

  • 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-28T04:09:42+00:00Added an answer on May 28, 2026 at 4:09 am

    A List<A extends B> and a List<B> are not the same, since to the first list you can only add A instances, and to the second you can add both A and B instances.

    This is all perfectly well explained in the Java generics tutorial, more specifically on page 4 (Section Generics and Subtyping)

    Edit

    A small example illustrating this and matching your code a bit more closely

    Map<Integer, List<List<? extends Number>>> a = new Hashtable<Integer,List<List<? extends Number>>>();
    List<List<Double>> b = new ArrayList<List<Double>>();
    a.put(0, b);//won't compile
    List<List<? extends Number>> c = new ArrayList<List<? extends Number>>(  );
    a.put( 1, c );//works perfectly
    

    The reason why this not compiles is explained in that PDF to which I linked, and to quote the relevant part

    Let’s test our understanding of generics. Is the following code snippet legal?

    List<String> ls = new ArrayList<String>(); //1
    List<Object> lo = ls; //2
    

    Line 1 is certainly legal. The trickier part of the question is line 2. This boils down
    to the question: is a List of String a List of Object. Most people’s instinct is to answer:
    “sure!”.
    Well, take a look at the next few lines:

    lo.add(new Object()); // 3
    String s = ls.get(0); // 4: attempts to assign an Object to a String
    

    I suggest to go through that whole PDF, and take a look at the (other) examples in that document.

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

Sidebar

Related Questions

I have :- Class Abc extends Activity(){ private ActivityManager am; private List<RunningAppProcessInfo> rList; @Override
I have class method that returns a list of employees that I can iterate
I have Class<? extends Object> class1 = obj.getClass(); Field[] fields = class1.getDeclaredFields(); for (Field
I have class that extends BroadcastReceiver and gets all new sms. When I get
I have: class MyClass extends MyClass2 implements Serializable { //... } In MyClass2 is
I have class with a member function that takes a default argument. struct Class
I have: class Car {..} class Other{ List<T> GetAll(){..} } I want to do:
I have class like public class ProgressBars { public ProgressBars() { } private Int32
I have class Person as following : class Person { char* name; int age;
I have class A that is supposed to inherit class B whose name is

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.