Skip to content

Instantly share code, notes, and snippets.

@rhmoller
Created July 17, 2011 11:51
Show Gist options
  • Save rhmoller/1087499 to your computer and use it in GitHub Desktop.
Save rhmoller/1087499 to your computer and use it in GitHub Desktop.
Java 7: Project Coin Examples
public void createGenerics() {
List<String> list = new ArrayList<String>();
Map<String, List<String>> keyValues = new HashMap<String, List<String>>();
}
public void createWithDiamondOperator() {
List<String> list = new ArrayList<>();
Map<String, List<String>> keyValues = new HashMap<>();
}
public void multiCatch(Class<MultiCatch> myClass) {
try {
Method method = myClass.getMethod("sayHello");
} catch (NoSuchMethodException | SecurityException e) {
// common exception handling logic
}
}
public void numericLiterals() {
int mask1 = 0b1000100010001000;
int mask2 = 0b1000_1000_1000_1000;
int color = 0xff_f0_fe_ff;
int price = 1_000_000;
double PI = 3.141_592_653_589_793d;
}
public void executeCommand(String command) {
switch (command) {
case "start":
startService();
break;
case "stop":
stopService();
break;
case "status":
showStatus();
break;
default:
unknownCommand();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment