Created
December 4, 2015 03:38
-
-
Save adeleinr/4995c0adeb6218b566c2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Try that autocloses of resources | |
================================= | |
try ( | |
InputStream in = new FileInputStream(src); | |
OutputStream out = new FileOutputStream(dest)) | |
{ | |
// code | |
} | |
Shorter and more concise Type deifnitions in generics | |
===================================================== | |
Before: | |
Map<String, List<String>> anagrams = | |
new HashMap<String, List<String>>(); | |
Now: | |
Map<String, List<String>> anagrams = new HashMap<>(); | |
String in case statement | |
======================== | |
String s = "foo"; | |
switch(s) { | |
case "quux": | |
processQuux(s); | |
// fall-through | |
case "foo": | |
case "bar": | |
processFooOrBar(s); | |
break; | |
} | |
Multiple exception catching | |
============================ | |
Before: | |
} catch (FirstException ex) { | |
logger.error(ex); | |
throw ex; | |
} catch (SecondException ex) { | |
logger.error(ex); | |
throw ex; | |
} | |
Now: | |
try{ | |
// Some code | |
} catch (FirstException | SecondException ex) { | |
logger.error(ex); | |
throw ex; | |
} | |
SafeVarargs | |
=========== | |
Before: | |
@SuppressWarnings({"unchecked", "varargs"}) | |
public static void printAll(List<String>... lists){ | |
for(List<String> list : lists){ | |
System.out.println(list); | |
} | |
} | |
Now: | |
@SafeVarargs | |
public static void printAll(List<String>... lists){ | |
for(List<String> list : lists){ | |
System.out.println(list); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment