본문 바로가기

Java22

[Lombok] @Builder.Default - @Builder 사용 시 필드값 초기화 방법 Lombok에서 @Builder 어노테이션 사용 시 필드 초기화를 하면 아래와 같은 경고가 발생하는 이유 및 해결방법! warning: @Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final. DTO에서 @Builder 어노테이션과 함께 필드 초기화를 하면 위와 같은 경고가 발생한다. 해석하자면, @Builder는 초기화 표현을 완전히 무시한다. 초기화 표현식으로 default.. 2023. 8. 13.
[Swagger3] 1. springdoc-openapi를 이용한 Swagger3 설정하기(+Swagger 옵션) Swagger 기본 설정 및 Swagger에서 제공하는 기본 옵션에 대해 알아보자! 1) build.gradle dependencies 안에 openapi-ui 추가 //swagger implementation 'org.springdoc:springdoc-openapi-ui:1.7.0' 2) application.yaml springdoc: api-docs: path: /api-docs# api-docs url: localhost:8080/api-docs groups: enabled: true# group 허용 swagger-ui: path: /index.html# swagger url : localhost:8080/swagger-ui/index.html enabled: true groups-order:.. 2023. 5. 5.
[트러블 슈팅] Reflection 객체 내 @Autowired NullPointerException 발생 1. 이슈 Reflection으로 동적 생성한 객체 내 @Autowired된 변수 접근 시 NPE(NullPointerException) 발생 2. 상세 내용 Reflection을 이용하여 객체를 동적으로 생성. -> method.invoke를 이용하여 객체 내 메서드를 실행 -> InvocationTargetException 발생. -> 원인을 확인해보니 실행된 메서드 내에서 @Autowired된 변수에 접근 시 NPE 발생 문제가 된 코드 Class targetClass = Class.forName(className); Object instance = targetClass.getDeclaredConstructor().newInstance(); Method method = targetClass.getD.. 2022. 10. 8.
[Java] 왜 배열은 Covariant(공변)이고 제네릭은 Invariant(불공변)일까? 자바에는 Variance(변성)이라는 개념이 있다. 변성은 타입의 계층 관계에서 서로 다른 타입 간에 어떠한 관계가 있는지 나타낸다. 변성의 개념은 자바의 Generic에서도 사용된다. 오늘의 주제인 Covariant(공변), Contravariant(반공변), Invariant(불공변)는 모두 변성의 한 종류이다. 각각의 개념을 간단하게 설명하면 아래와 같다. Covariant - SubType[]은 SuperType[]이다. (ex - String[]은 Object[]이다.) Contravariant - SuperType[]은 SubType[]이다. (ex - Object[]은 String[]이다.) Invariant - SubType[]은 SuperType[]이 아니고, SuperType[]은 Su.. 2022. 7. 22.
[Java] Covariant Return Type이란? 객체지향 프로그래밍에서 메소드의 Covariant Return Type이란 서브 클래스에서 오버라이딩된 메소드의 리턴 타입을 “더 좁은" 타입으로 지정할 수 있는 것이다. * 자바의 Covariant(공변)에 대한 자세한 내용은 다음 게시글을 보면 도움이 된다. 자바에서 Covariant Return Type은 Java 1.5부터 허용되었다. 코드로 확인해보자. 예를 들어 B가 A를 상속받는 subclass라고 하고, A타입을 반환하는 C의 get() 메소드를 오버라이딩할 때 똑같이 A를 반환하지 않고 A의 서브타입인 B를 반환해도 문제가 발생하지 않는다. (원래 오버라이딩한 메소드에서 리턴타입이 맞지 않을 경우 컴파일 타임에 The return type is incompatible with ... 라는.. 2022. 7. 15.
[Java] Collection - 1. Collection Framework 1. Collection Interface 2. Iterable Interface 3. List Interface 1) ArrayList 2) LinkedList 3) Vector 4. Stack Interface 5. Queue Interface 1) PriorityQueue 6. Set Interface 7. SortedSet Interface 8. Map Interface 1) HashMap * 아래 링크를 참고하여 번역 및 추가 정리 하였습니다. https://www.geeksforgeeks.org/collections-in-java-2/ Collections in Java - GeeksforGeeks A Computer Science portal for geeks. It contains well.. 2022. 7. 5.
[Java] Collection.stream().forEach() 와 Collection.forEach() 의 차이 * 아래 링크를 참고하여 번역 및 내용을 추가하여 정리하였습니다. https://www.geeksforgeeks.org/difference-between-collection-stream-foreach-and-collection-foreach-in-java/?ref=rp Difference Between Collection.stream().forEach() and Collection.forEach() in Java - GeeksforGeeks A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and.. 2022. 6. 27.
[Java] 2. Garbage Collection - GC의 과정 및 종류 1. Garbage Collection 과정 모든 GC 알고리즘은 Mark & Sweep 2가지 기본 작업을 수행한다. Step 1. Mark 가비지 컬렉터가 어떤 객체가 사용되고 어떤 객체가 사용되지 않는지 식별하는 과정 객체가 생성되면 객체의 mark bit를 0으로 세팅한다. Mark 단계에서는 모든 reachable 객체에 bit를 1(true)로 마킹한다. 마킹 작업은 단순 그래프 탐색을 요구하기 때문에 깊이우선 탐색을 이용한다. root는 객체를 참조하는 지역변수로, root가 여러 개일 경우 모든 root들에 대해 Mark()를 수행한다. 객체가 처음 생성되면 객체의 mark bit를 0으로 세팅하고 Mark 단계에서 모든 reachable 객체에 bit를 1(true)로 마킹한다. 마킹 작.. 2022. 6. 24.
[Java] 1. Garbage Collection이란? GC의 핵심 및 과정 백엔드 개발자라면 면접에서 99% 물어보는 Garbage Collection(GC)에 대해 확실하게 정리하고 넘어가보자. * 아래 링크를 참고하여 번역 및 정리하였습니다. https://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html https://www.geeksforgeeks.org/garbage-collection-java/?ref=gcse Garbage Collection in Java - GeeksforGeeks A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and.. 2022. 6. 24.
반응형