Skip to content

Instantly share code, notes, and snippets.

@samandmoore
Created May 15, 2013 16:56
Show Gist options
  • Select an option

  • Save samandmoore/5585466 to your computer and use it in GitHub Desktop.

Select an option

Save samandmoore/5585466 to your computer and use it in GitHub Desktop.
java doesn't have var, so if you want to type less, you have to create a static factory...
// problem
Map<String, List<String>> map = new HashMap<String, List<String>>();
// --------------------------------------------------
// Java solution
public static <K, V> HashMap<K, V> newHashMap() {
return new HashMap<K, V>();
}
// Java result
Map<String, List<String>> map = newHashMap();
// --------------------------------------------------
// C# solution
the `var` keyword for type inference...
// C# result
var map = new Map<String, List<String>>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment