본문 바로가기
728x90
반응형

개발 관련 강의 정리/자바의정석3

[자바의 정석] 스트림 정리 ch14-15,16 스트림, 스트림의 특징 스트림 - 다양한 데이터 소스(컬렉션, 배열)를 표준화된 방법으로 다루기 위한 것 List list = Arrays.asList(1, 2, 3, 4, 5); Stream intStream = list.stream(); Stream strStream = Stream.of(new String[]{"a", "b", "c"}); // 배열 Stream evenStream = Stream.iterate(0, n -> n + 2); // 0,2,4,6 ... Stream randomStream = Stream.generate(Math::random); // 람다식 IntStream intStream = new Random().ints(5); // 난수 스트림(크기가 5) .. 2023. 7. 10.
[자바의 정석 - 기초편] 람다 정리 [자바의 정석 - 기초편] 람다 람다식 - 함수(메서드)를 간단한 식으로 표현하는 방법 람다식 작성 1. 메서드의 이름과 반환타입 제거하고 '->'를 블록{} 앞에 추가 int max(int a, int b) { return a > b ? a : b; } -> int max(int a, int b) -> { return a > b ? a : b; } 2. 반환값이 있는 경우, 식이나 값만 적고 return문 생략 가능(끝에 ';' 안 붙임) (int a, int b) -> { return a > b ? a : b; } -> (int a, int b) -> a > b ? a : b 3. 매개변수의 타입이 추론 가능하면 생략가능 (int a, int b) -> a > b ? a : b -> (a, b) ->.. 2023. 4. 20.
[자바의정석] 애너테이션 정리 [자바의 정석 - 기초편] ch12-23~26 표준애너테이션 package test; class Parent { void parentMethod() { } } class Child extends Parent { @Override @Deprecated void parentMethod() { } } @FunctionalInterface // 함수형 인터페이스는 하나의 추상 메서드만 가능 interface Testable { void test(); // 추상 메서드 // void check(); // 추상 메서드 } public class Test { public static void main(String[] args) { Child c = new Child(); c.parentMethod(); // depr.. 2023. 4. 19.
728x90
반응형