1. Improved Type Inference for Generic Instance Creation

 - 단순해진 Generics
이전 : 
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
JDK7 :
Map<String, List<String>> anagrams = new HashMap<>();
 - 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000009.html

2. Language support for collections
 - Java 코드의 사이즈를 줄여주고, 가독성을 높여줌
이전 :
final List<Integer> piDigits =
Collections.unmodifiableList(Arrays.asList(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9 ));
JDK7 :
final List<Integer> piDigits = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9];
 - 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/001193.html

3. Automatic Resource Management
 - exception handling을 줄여줌
 - C++’s RAII과 C#’s using에 대응하기 위함
이전 :
static String readFirstLineFromFile(String path) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
br.close();
}
}
JDK7 :
static String readFirstLineFromFile2(String path) throws IOException {
try (BufferedReader br = new BufferedReader(new FileReader(path)) {
return br.readLine();
}
}
 - 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000011.html

4. Added binary integer literals
 - Integer Literal에 Binary Integer Literal이 추가됨
BinaryIntegerLiteral:
BinaryNumeral IntegerTypeSuffix_opt
BinaryNumeral:
0 b BinaryDigits
0 B BinaryDigits
BinaryDigits:
BinaryDigit
BinaryDigit BinaryDigits
BinaryDigit: one of
0 1
 - 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000929.html

5. String literals in switch statements
 - 스위치문에 문자열 사용 가능
JDK7 :
String s = "first";
switch(s) {
case "first":
processFirst(s);
case "second":
case "third":
processThird(s);
break;
case "fourth":
processFourth(s);
default:
processDefault(s);
break;
}
 - 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000001.html

6. Simplified Varargs Method Invocation
 - 컴파일 경고에서 메소드 선언 경고로 이동함
이전 :
static <T> List<T> asList(T... elements) { ... }
static List<Callable<String>> stringFactories() {
Callable<String> a, b, c;
...
*// Warning: **"uses unchecked or unsafe operations"*
return asList(a, b, c);
}
JDK7 :
*// Warning: **"enables unsafe generic array creation"*
static <T> List<T> asList(T... elements) { ... }

static List<Callable<String>> stringFactories() {
Callable<String> a, b, c;
...
return asList(a, b, c);
}
 - 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000217.html

7. Enhanced null handling
 - Null-ignore invocation, Null-safe types
이전 :
String str = getStringMayBeNull();
str = (str == null ? "" : str);
JDK7 :
String str = getStringMayBeNull() ?: "";
 - 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000217.html

8. Enum Comparisons
 - Enum에서 range(<, > 등) 연산 가능
이전 :
if(rank1.compareTo(rank2) < 0) ...
if(rank1.ordinal() < rank2.ordinal()) ...
JDK7 :
if(rank1 < rank2) ...
9. Chained Invocation
 - 체인형식으로 메소드 호출 가능
이전 :
DrinkBuilder margarita = new DrinkBuilder();
margarita.add("tequila");
margarita.add("orange liqueur");
margarita.add("lime juice");
margarita.withRocks();
margarita.withSalt();
Drink drink = margarita.drink();
JDK7 :
Drink margarita = new DrinkBuilder()
.add(“tequila”)
.add(“orange liqueur”)
.add(“lime juice”)
.withRocks()
.withSalt()
.drink();
10. Extension Methods
 - static import 확장
이전 :
List list = new ArrayList();
...
Collections.sort(list);
list.sort();
JDK7 :
import static java.util.Collections.sort;
List list = new ArrayList();
...
list.sort();
 - 레퍼런스 : http://www.javac.info/ExtensionMethods.html

11. Improved Exception Handling
 - 두개이상의 catch문 가능
 - catch문에서 rethrow가능
JDK7 : catch multiple exceptions
try {
return klass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new AssertionError(e);
}
JDK7 : rethrow exceptions
try {
doable.doIt();
} catch (final Throwable ex) {
logger.log(ex);

// surrounding method can declare only checked thrown by doIt()
throw ex;
}
 - 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000003.html

12. Language support for JSR 292
 - 다이나믹 타입 지원(java.dyn.Dynamic)
JDK7 :
Dynamic x = (any type of expression can go here);
Object y = x.foo("ABC").bar(42).baz();

+ Recent posts