Skip to content

Instantly share code, notes, and snippets.

@2013techsmarts
Last active February 15, 2017 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2013techsmarts/e056f9653d0131b09fa1f22764eaa0a4 to your computer and use it in GitHub Desktop.
Save 2013techsmarts/e056f9653d0131b09fa1f22764eaa0a4 to your computer and use it in GitHub Desktop.
Demonstration of Immutable Map
jshell> Map immutableMap = Map.of(1,"Smart",2,"Techie");
immutableMap ==> {1=Smart, 2=Techie}
//Get item from Map
jshell> immutableMap.get(1);
$2 ==> "Smart"
//Add item to map
jshell> immutableMap.put(3,"Smart_1");
| Warning:
| unchecked call to put(K,V) as a member of the raw type java.util.Map
| immutableMap.put(3,"Smart_1");
| ^---------------------------^
| java.lang.UnsupportedOperationException thrown:
| at ImmutableCollections.uoe (ImmutableCollections.java:70)
| at ImmutableCollections$AbstractImmutableMap.put (ImmutableCollections.java:557)
| at (#3:1)
jshell>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment