Last active
September 20, 2015 14:15
-
-
Save smamran/bd99e86143a5d478173f to your computer and use it in GitHub Desktop.
Generics vs Non Generics Java
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
// The following code snippet without generics requires casting: | |
List list = new ArrayList(); | |
list.add("hello"); | |
String s = (String) list.get(0); | |
// When re-written to use generics, the code does not require casting: | |
List<String> list = new ArrayList<String>(); | |
list.add("hello"); | |
String s = list.get(0); // no cast |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment