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.
You should always code to an interface. ie. in this case you should declare your field like this:
This way anything using the
mapvariable will treat it as typeMaprather thanHashMap.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
HashMapRead through this question: What does it mean to "program to an interface"?
Also I am not sure what you were doing casting to a
Setthere?