Skip to content

Instantly share code, notes, and snippets.

@prashant4224
Created May 28, 2020 17:31
Show Gist options
  • Save prashant4224/c60bcfa70ae5051aabc4360735f40ec6 to your computer and use it in GitHub Desktop.
Save prashant4224/c60bcfa70ae5051aabc4360735f40ec6 to your computer and use it in GitHub Desktop.
/* Immutable Class */
public final class Box {
private final String key;
private final String value;
private final HashMap<String, String> hm;
public Box(String key, String value, HashMap<String, String> hm) {
this.key = key;
this.value = value;
HashMap<String, String> hmTest = new HashMap<>();
for (Map.Entry<String, String> hmEntry : hm.entrySet()){
htTest.put(hmEntry.getKey(), hmEntry.getValue());
}
this.hm = hmTest;
}
//No setters
public String getKey() {
return key;
}
public String getValue() {
return value;
}
public HashMap<String, String> getHm() {
return (HashMap<String, String>)hm.clone();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment