1. Improved Type Inference for Generic Instance Creation
- 단순해진 Generics
이전 :- 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000009.html
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
JDK7 :
Map<String, List<String>> anagrams = new HashMap<>();
2. Language support for collections
- Java 코드의 사이즈를 줄여주고, 가독성을 높여줌
이전 :- 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/001193.html
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];
3. Automatic Resource Management
- exception handling을 줄여줌
- C++’s RAII과 C#’s using에 대응하기 위함
이전 :- 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000011.html
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();
}
}
4. Added binary integer literals
- Integer Literal에 Binary Integer Literal이 추가됨
BinaryIntegerLiteral:- 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000929.html
BinaryNumeral IntegerTypeSuffix_opt
BinaryNumeral:
0 b BinaryDigits
0 B BinaryDigits
BinaryDigits:
BinaryDigit
BinaryDigit BinaryDigits
BinaryDigit: one of
0 1
5. String literals in switch statements
- 스위치문에 문자열 사용 가능
JDK7 :- 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000001.html
String s = "first";
switch(s) {
case "first":
processFirst(s);
case "second":
case "third":
processThird(s);
break;
case "fourth":
processFourth(s);
default:
processDefault(s);
break;
}
6. Simplified Varargs Method Invocation
- 컴파일 경고에서 메소드 선언 경고로 이동함
이전 :- 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000217.html
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);
}
7. Enhanced null handling
- Null-ignore invocation, Null-safe types
이전 :- 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000217.html
String str = getStringMayBeNull();
str = (str == null ? "" : str);
JDK7 :
String str = getStringMayBeNull() ?: "";
8. Enum Comparisons
- Enum에서 range(<, > 등) 연산 가능
이전 :9. Chained Invocation
if(rank1.compareTo(rank2) < 0) ...
if(rank1.ordinal() < rank2.ordinal()) ...
JDK7 :
if(rank1 < rank2) ...
- 체인형식으로 메소드 호출 가능
이전 :10. Extension Methods
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();
- static import 확장
이전 :- 레퍼런스 : http://www.javac.info/ExtensionMethods.html
List list = new ArrayList();
...
Collections.sort(list);
list.sort();
JDK7 :
import static java.util.Collections.sort;
List list = new ArrayList();
...
list.sort();
11. Improved Exception Handling
- 두개이상의 catch문 가능
- catch문에서 rethrow가능
JDK7 : catch multiple exceptions- 레퍼런스 : http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000003.html
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;
}
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();
'Java > Language' 카테고리의 다른 글
java.lang.Annotation(주석:@) (0) | 2009.11.16 |
---|---|
[펌]괜찮은 Java 사이트들 (0) | 2009.10.26 |
[펌]Silicon Valley Code Code Camp 2009 Trip Report (0) | 2009.10.05 |
JDK7 new numeric litteral formats (JDK에 새로운 상수 형식들) (0) | 2009.09.25 |
자주 발생하는 에러와 해결방법 (0) | 2009.09.08 |