Skip to content

Instantly share code, notes, and snippets.

@smamran
Last active September 20, 2015 14:15
Show Gist options
  • Save smamran/bd99e86143a5d478173f to your computer and use it in GitHub Desktop.
Save smamran/bd99e86143a5d478173f to your computer and use it in GitHub Desktop.
Generics vs Non Generics Java
// 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