Java 5 SE
2004. 9. 30. Released.
Summary
- 제너릭 Generics: provides compile-time (static) type safety for collections and eliminates the need for most typecasts (type conversion) (specified by JSR 14)
- 메타데이터 Metadata 어노테이션 Annotation
@: allows language constructs such as classes and methods to be tagged with additional data, which can then be processed by metadata-aware utilities (specified by JSR 175) - 오토박싱/언박싱 Autoboxing/unboxing (Wrapping): automatic conversions between primitive types (such as int) and primitive wrapper classes (such as Integer) (specified by JSR 201)
- 열거형 Enumerations
enum: the enum keyword creates a typesafe, ordered list of values (such as Day.MONDAY, Day.TUESDAY, etc.); previously this could only be achieved by non-typesafe constant integers or manually constructed classes (typesafe enum pattern) (specified by JSR 201) - 가변인수 Varargs: the last parameter of a method can now be declared using a type name followed by three dots (e.g. void drawtext(String… lines)); in the calling code any number of parameters of that type can be used and they are then placed in an array to be passed to the method, or alternatively the calling code can pass an array of that type
- 향상된
foreach 루프: the for loop syntax is extended with special syntax for iterating over each member of either an array or any Iterable, such as the standard Collection classes (specified by JSR 201) - Improved semantics of execution for multi-threaded Java programs; the new Java memory model addresses issues of complexity, effectiveness, and performance of previous specifications
- 정적 임포트 Static imports
standard libraries 변경점:
- Automatic stub generation for RMI objects
- Swing: New skinnable look and feel, called synth
- 동시성 유틸(
java.util.concurrent) - Scanner class for parsing data from various input streams and buffers
Description
- Generics
- Annotations:
@metadata - Autoboxing/unboxing: 기본 자료형에 대응되는 객체에 대해 자동으로 캐스팅
- Enumerations:
enumkeyword- `enum`
- `EnumSet`
- `EnumMap`
- Varagrs: `…`가변길이 파라미터, 가변인자
- 기존: 매개변수나 컬렉션이나 배열 사용
- method(type `…`variable)
void sum (String ... str) { ... }
- 내부적으로 배열을 생성
- 가변인자는 마지막에 선언
- 가변인자는 컴파일러 타입선택 어려움 → 가능한 오버로딩 하지 말것
- for in:
for (:) - Static imports: 정적 임포트. static 멤버를 호출 할 때 클래스명을 생략 가능.
import static java.lang.Math.random; System.out.println(Math.random());
- API
- Concurrency API: 동시성(병렬프로그램) 지원
java.util.concurrent - scanner class