Last active
February 15, 2017 17:24
-
-
Save 2013techsmarts/e056f9653d0131b09fa1f22764eaa0a4 to your computer and use it in GitHub Desktop.
Demonstration of Immutable Map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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