람다식@FunctionalInterfaceinterface MyLambdaFunction { int max(int a, int b);}public class Main { public static void main(String[] args) { // 람다식을 이용한 익명함수 MyLambdaFunction lambdaFunction = (int a, int b) -> a > b ? a : b; System.out.println(lambdaFunction.max(3, 5)); }} 람다식 메소드 참조(x, y) -> Math.max(x, y)(x, y) 중복 , 리턴 값이 또 다른 메서드 호출Math::max;@FunctionalInterfaceinter..
프로그래밍
스트림 문법 반환타입메서드booleanallMatch(Predicate T> predicate)Returns whether all elements of this stream match the provided predicate.booleananyMatch(Predicate T> predicate)Returns whether any elements of this stream match the provided predicate.static Stream.Builderbuilder()Returns a builder for a Stream. Rcollect(Collector T,A,R> collector)Performs a mutable reduction operation on the elements of thi..
! 클래스 다이어그램 Toolhttps://draw.iohttps://staruml.io/ Refactoring GURU // 디자인패턴 추천23가지 패턴 정리
OptionalNPE (NullPointerException) : 개발을 할 때 가장 많이 발생하는 예외Optional는 null이 올 수 있는 값을 감싸는 Wrapper 클래스로, 참조하더라도 NPE가 발생하지 않도록 도와준다.Optional.of() - 값이 Null이 아닌 경우Optional.ofNullbale() - 값이 Null일수도, 아닐수도 있는 경우Optional은 값을 Wrapping하고 다시 풀고, null 일 경우에는 대체하는 함수를 호출하는 등의 오버헤드가 있으므로잘못 사용하면 시스템 성능이 저하된다.자바에서는 거의 모든것이 래퍼런스 -> 거의 모든것이 null이 될 수 있다.메소드의 반환 값이 절대 null이 아니라면 Optional을 사용하지 않는 것이 좋다.출처: https:..
스트림데이터 소스를 변경하지 않는다.일회용이다작업을 내부 반복으로 처리한다.데이터의 연속이다Collections.stream() 을 제공 (Java8) 스트림 연산 중간연산 : 연산 결과가 스트림인 연산. 스트림에 연속해서 중간 연산할 수 있음최종 연산 : 연산 결과가 스트림이 아닌 연산. 스트림의 요소를 소모하므로 단 한번만 가능 stream.distinct().limit(5).sorted().forEach(System.out::println) 중간 연산 중간 연산 중간 연산 최종 연산스트림의 최종 연산forEach() : 스트림의 요소를 출력하는 용도findFirst() : 스트림의 요소 중에서 조건에 일치하는 첫 번째 것을 반환, 주로 f..
OptionalOptional지네릭 클래스로 'T타입의 객체'를 감싸는 래퍼 클래스이다. Optional 타입의 객체에는 모든 타입의 참조변수를 담을 수 있다.최종 연산의 결과를 그냥 반환하는게 아니라 Optional 객체에 담아서 반환함반환된 결과가 null인지 매번 if문으로 체크하는 대신 Optional에 정의돈 메서드를 통해서 간단히 처리할 수 있다. Optional객체 생성하기of() / ofNullable() Optional 객체의 값 가져오기get()을 사용한다.값이 Null일 때는 NoSuchElementException이 발생하며, 이를 대비해서 orElse()로 대체할 값을 지정할 수 있다.