In my case I have this to manipulate a shallow copy of given HashMap
public class SomeClass
{
private HashMap<String, String> hashMap;
public SomeClass( private HashMap<String, String> hashMap )
{
this.hashMap = (HashMap<String, String>) hashMap.clone();
}
}
However eclipse suggests me to extract to local variable or method or add a cast and when I do so it keeps suggesting me same solutions :)
I've came to this post and from the accepted answer I dont find it very clear
"you're wasting memory with the new HashMap creation call"
And when I apply that to my code I'll have
if(songData.clone() instanceof HashMap)
{
this.songData = (HashMap<String, String>) songData.clone();
}
I find that cosume more process as calling clone()
twice.
Is there a better way to do this? Could my snippet be harmful to resouces?