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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:50:55+00:00 2026-05-20T04:50:55+00:00

In short I’m trying to write an AbstractMap implementation and I encountered a syntax

  • 0

In short I’m trying to write an AbstractMap implementation and I encountered a syntax problem that I do not understand.

Consider the following two sketches (the identifiers with My before them are custom types).


(1) Not Working:

public class CustomMap extends AbstractMap<MyKey,MyValue> {
    private Set<Map.Entry<MyKey,MyValue>> data = null ;
    public static class MyMapEntry<K,V> implements Map.Entry<K,V> { 
        //...
    }
    public static class MyEntrySet<E> extends AbstractSet<E> {
        //...
    }
    public static class MyEntrySetIterator<E> implements Iterator<E> {
        //...
    }
    { // initializer block
        this.data = new MyEntrySet<MyMapEntry<MyKey,MyValue>>() ;
    }
    // (constructors and methods of the Map interface)

}

(2) Working:

public class CustomMap extends AbstractMap<MyKey,MyValue> {
    private Set<Map.Entry<MyKey,MyValue>> data = null ;
    public static class MyMapEntry<K,V> implements Map.Entry<K,V> { 
        //...
    }
    public static class MyEntrySet<E> extends AbstractSet<E> {
        //...
    }
    public static class MyEntrySetIterator<E> implements Iterator<E> {
        //...
    }
    { // initializer block
        this.data = new MyEntrySet<Map.Entry<MyKey,MyValue>>() ;
    }
    // (constructors and methods of the Map interface)

}

The only difference is in the way I instantiated this.data (the Set backing the Map): apparently the compiler does not accept an instance of Map.Entry (such as MyMapEntry) as the parameterized type of MyEntrySet.

The compiler complains about “incompatible types”.

I wonder why.

Please post comments in case I need to elaborate,
TIA,

FK82

  • 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-20T04:50:56+00:00Added an answer on May 20, 2026 at 4:50 am

    I’ll expand on the other answers with a simpler example.

    Consider

    List<String> strings = new ArrayList<String>();
    List<Object> objects = strings; // this is what you are doing in your constructor
    objects.add("some string");
    

    objects has declared that it will only contain Objects, and strings has declared that it will only contain Strings. So surely assigning strings to objects should be fine as all Strings are Objects? We’re even allowed to add Strings to objects without a problem.

    However, what about this situation.

    objects.add(new Object());
    

    Since objects is just strings, we are adding an Object to strings, and thus breaking its declaration that it will only contain Strings.

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

Sidebar

Related Questions

Short Version (tl;dr): Is there an open source or commercial engine that provides embeddable
Short version: I want to trigger the Form_Load() event without making the form visible.
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific
Short of cutting and pasting, is there a way to sort the methods in
Short of putting a UIWebView as the back-most layer in my nib file, how
Short: how does modelbinding pass objects from view to controller? Long: First, based on
Short version: assuming I don't want to keep the data for long, how do
Short of copying the entire .netbeans directory is there any way to transfer custom
Short Version: When I've created a Channel using ChannelFactory on a client which uses
Short of inserting a try/catch block in each worker thread method, is there a

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.