Introducing
Your new presentation assistant.
Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.
Trending searches
Default method 지원
인터페이스의 Abstract Method들에 대한 기본기능을 지정
public interface Student {
default void readBook(){
System.out.println("reading book");
}
}
public class GoSam implements Student {
public static void main(String ar[]){
GoSam gosam = new GoSam();
gosam.readBook();
}
}
완전히 새롭게 개발
JAVA 8 이전
public interface TestInterface {
public void action(){
System.out.println("Test");
}
}
Joda-Time과 유사한 모습이지만, 더 개선된 모습
Abstract methods do not specify a body!!
불변 객체가 아니다(not immutable)
Calendar 객체나 Date 객체가 여러 객체에서 공유되면?
int 상수 필드의 남용
calendar.add(Calendar.SECOND, 2); // 컴파일 에러 없음
헷갈리는 월 지정
calendar.set(1582, Calendar.OCTOBER , 4); // 실제로는 9
시대에 뒤떨어지는 API : java.util.Date API Doc
람다식(Lambda Expression)
자바 8은 단순히 람다를 도입할 뿐 아니라,
새 날짜 API
람다식의 효과적인 사용 방법을 안내하고 유도
→ 기존 API에 람다를 대폭 적용
인터페이스(Interface) 업데이트
컬랙션(Collection)을 다루는 새로운 방법을 제공
스트림(Stream) API
기존
등등 ...
Collections.sort(theListOfMyClasses, new Comparator<MyClass>() {
public int compare(MyClass a, MyClass b) {
return b.getValue() - a.getValue();
}
});
Concurrency API의 확장
IO/NIO API의 확장
JAVA 8
Project Nashorn : 자바스크립트 엔진
java.util.Map에 default Method들이 추가
자바FX 8
theListOfMyClasses.sort((MyClass a, MyClass b) -> {
return a.getValue() - b.getValue();
});
자바 타입 어노테이션
등등 ..
Parallelism
자바 8의 람다식 문법
Processing elements with an explicit for-loop is inherently serial
int sumOfWeights = widgets.parallelStream()
.filter(b -> b.getColor() == RED)
.mapToInt(b -> b.getWeight())
.sum();
theListOfMyClasses.sort((MyClass a, MyClass b) -> {
return a.getValue() - b.getValue();
});
theListOfMyClasses.sort((a, b) -> a.getValue() - b.getValue());
Because..
Pipe and Filter Design Pattern
두 가지의 Operator
• Intermediate Operator
Stream 을 받아서 Stream 을 돌려줌
ex) sorted, filter ..
• Final Operator
Stream 을 받아서 최종 결과 계산
ex) min/max, sum ..
벽돌들 중 색이 빨간색인 벽돌들의 무게의 합을 구하는 코드
List<Block> blocks = /* ... */;
int sum = 0;
for (Block block : blocks) {
if (block.getColor() == Color.RED) {
sum += block.getWeight();
}
}
List<Block> blocks = /* ... */;
int sum = blocks.stream()
.filter(b -> b.getColor() == Color.RED)
.map(b -> b.getWeight())
.sum();