Java 7 Type Inference for Generic Instance Creation <font size=-2><a href=http://www.lifemichael.com/en/acronyms/>PRO</a></font>

As of Java 7 we can take out the type arguments required to instantiate a generic class as long as the compiler can infer the type arguments from the context. Many developers name the remaining pair of angle brackets as ‘diamond’. package com.abelski.samples; import java.util.LinkedList; import java.util.List; public class GenericsTypeInference { public static void main(String[] […]

Java 7 Switch Case <font size=-2><a href=http://www.lifemichael.com/en/acronyms/>PRO</a></font>

As of Java 7 we can write a switch case statement that works on strings. This new capability might assist us with writing a shorter code. package com.abelski.samples; public class Demo { public static void main(String[] args) { String operator = args[1]; double numA = Double.parseDouble(args[0]); double numB = Double.parseDouble(args[2]); String result; switch(operator) { case […]