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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:04:08+00:00 2026-05-30T19:04:08+00:00

Is there a reason why Eclipse reports type safety warning in the following declaration?

  • 0

Is there a reason why Eclipse reports type safety warning in the following declaration?

Map<String,List<Map<String, ParseNode>>> mapX = new HashMap();

I understand that all mapX usages would be strongly typed but what can possibly be achieved by java generics insisting on providing HashMap paramaterized type (other than adding noise to the code)?

  • 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-30T19:04:10+00:00Added an answer on May 30, 2026 at 7:04 pm

    Your declaration is invalid.

    Using Generics (Parameterized Types)

    Using Java 5 to 6, you should write:

    Map<String, List<Map<String, ParseNode>>> m =
        new HashMap<String, List<Map<String, ParseNode>>>();
    

    Starting with Java 7, you can simplify this with:

    Map<String, List<Map<String, ParseNode>>> m = new HashMap<>();
    

    Your syntax means something different and uses a raw type:

    Map<String, List<Map<String, ParseNode>>> m = new HashMap();
    

    Update:

    To answer your question, this has implications (as mentioned by the Java Tutorial):

    Note that to take advantage of automatic type inference during generic
    class instantiation, you must specify the diamond. [In your case] the
    compiler generates an unchecked conversion warning
    because the HashMap() constructor refers to the HashMap raw type, not
    the [parameterized Map] type.

    Basically meaning that the parameterization of your type here doesn’t have much meaning.
    The code following this declaration will be compiled with the assumptation that it contains values with the types as declared. However at runtime, you declared a type of a raw type, and you could very well have assigned a map containing different values to this entry.

    What you wrote would be the equivalent of writing something like:

    Map rawMap = new HashMap();
    rawMap.add("string", "not list!");
    
    Map<String, List<Map<String, ParseNode>>> m = rawMap; // uh oh!!
    

    Which would compile fine, and blow up in your face at runtime when you try to access one of m‘s values as a List<Map<String, ParseNode>>.

    Reasons

    The reason for this is that Generics where introduced while conserving complete backwards compatibility at the source level, hence some of their limitation, like:

    • the impossibility to have a short-hand form without at least some indicator for generics support (here, the so-called diamond operator <>),
    • the impossibility to inspect generic-types at runtime, because they had to be implemented with Type Erasure.

    Further Reading

    • From The Java Tutorial:
      • section on Generic Types
      • section on Type Inference and Instantiation of Generic Classes
    • From the Java Language Specifications (JLS):
      • Java SE 5’s JLS section on Types, Values and Variables
      • Java SE 7’s JLS section on Types, Values and Variables
    • From good StackOverflow questions:
      • What is the point of the diamond operator in Java 7?
      • Java Raw Type and generics interaction
    • Others:
      • IBM Developer Series: Java Theory and Practice: Generics Gotchas
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any reason to prefer a CharBuffer to a char[] in the following:
I was wondering if there is a specific reason, why my eclipse product .exe
I installed eclipse galileo from kubuntu package manager. For some reason, there is no
Recently I imported a new project to Eclipse Indigo IDE. Initially there is no
If one is using Eclipse EE is there any reason to use the Java
Is there any reason not to use the bitwise operators &, |, and ^
Is there any reason something like this would not work? This is the logic
Is there any reason why I should pick JSON over XML, or vice-versa if
Is there any reason to use a varchar field instead of a date field
Is there any reason to start a GUI program (application for Windows) written in

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.