Skip to content

Instantly share code, notes, and snippets.

@benjjo
Created January 27, 2020 19:57
Show Gist options
  • Select an option

  • Save benjjo/dd3a2637f8d73771004afd1f36f52f24 to your computer and use it in GitHub Desktop.

Select an option

Save benjjo/dd3a2637f8d73771004afd1f36f52f24 to your computer and use it in GitHub Desktop.
import java.util.*;
class Test{
public static final Map<String,Integer> MYHASH;
static{
Hashtable<String,Integer> tmp =
new Hashtable<String,Integer>();
tmp.put("A",65);
tmp.put("C",67);
MYHASH = Collections.unmodifiableMap(tmp);
}
public static void main(String[] args){
System.out.println(MYHASH.get("A"));
//this will throw
//java.lang.UnsupportedOperationException
MYHASH.put("B",66);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment