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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:00:56+00:00 2026-06-17T15:00:56+00:00

I am getting this warning on Sonar: Avoid using implementation types like ‘HashMap’; use

  • 0

I am getting this warning on Sonar:

Avoid using implementation types like ‘HashMap’; use the interface
instead

What does it mean?

The class in which i get this warning is as:

class A {
   private HashMap<String, String> map=new HashMap<String, String>();

   //getters and setters

}

Please, I want proper solution to avoid warning on Sonar.

  • 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-17T15:00:57+00:00Added an answer on June 17, 2026 at 3:00 pm

    You should always code to an interface. ie. in this case you should declare your field like this:

    private Map<String, String> map= new HashMap<String, String>();
    

    This way anything using the map variable will treat it as type Map rather than HashMap.

    This allows you to swap out the underlying implementation of your map at a later date without having to change any code. You are no longer tied to HashMap

    Read through this question: What does it mean to "program to an interface"?

    Also I am not sure what you were doing casting to a Set there?

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

Sidebar

Related Questions

I keep getting this as a warning I want to avoid getting this warning
Getting red warning message that expected identifier for this statement CALayer = ImageView.layer; Using
Thanks in advance. Getting this warning when using below code: Warning: file_get_contents(test.php) [function.file-get-contents]: failed
I am getting this warning even though i am using webxml in my ANT
I'm getting this warning (after use diagnostics;); Parsing of undecoded UTF-8 will give garbage
I'm getting this warning (below) when trying to use NSDateFormatter. I am importing in
I'm getting this warning message when I try using Segmented control with style Rounded
I'm getting this warning for a plugin I'm using: DEPRECATION WARNING: class_inheritable_attribute is deprecated,
i am getting this warning while using lib2xml in my code. warning: Unable to
I am getting this warning: Use of uninitialized value in eval \string\ at myscript.pl

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.