전체 글
-
정수(Primitive type) 배열을 리스트로 변환하기오답 노트 2023. 10. 13. 11:19
아주 간단한 문제였으나, 의외로(?) 나는 헤매이고 있었다. 정수형 Primitive type인 int 배열을 자바에서 제공해주는 Util 클래스인 Arrays를 활용해 손쉽게 List로 변경할 수 있을 것이라 생각했지만, 큰 착각이었다. 너무나도 당연하게 오토 박싱 작업이 진행되고 너무나도 당연히 List 형태로 int를 활용할 수 있을 것이라 생각했다. int[] primitiveArr = {1, 2, 3}; // int 형의 배열 List ints = Arrays.asList(primitiveArr); // Arrays.asList를 활용하였으나 // 결과는 List를 반환!! 결과는 List 이라는 해괴한 모습의 리스트가 만들어져버렸다💩 조금 찾아보니 이 이뉴는 유형 비호환성으로 인한 오토 박싱 ..
-
자바 JDK 9 부터 JDK17까지의 주요 코딩 특징스터디 노트 2023. 10. 12. 20:57
아래 자료들은 최범균님의 영상을 보고 제작하였습니다. 원본 강의 영상 : https://youtu.be/7SlDdzVk6GE?si=adWuAndOQHY-40Pk JDK 9 📌 JDK8에서 인터페이스에 default 메서드와 static 메서드를 선언할 수 있게 되었는데, 9에서는 private 메서드도 추가할 수 있게 되었음. public interface Client { void exchange(); default void get() { logging2("before"); exchange(); logging("call get"); } private void logging(String msg) { System.out.println(msg); } private void logging2(String msg)..
-
[Java] 객체 필드 Validation 손쉽게 구현하기 (feat. Bean Validation & @NotNull)스터디 노트 2023. 10. 12. 14:04
가끔 Domain을 구성하다 보면 자연스레 필수적으로 받아야만 하는 데이터들이 있다. 예를 들어 보면 Account라는 계좌 정보를 나타내는 Domain이 있다고 해보겠다. @Getter @AllArgsConstructor public class Account { private String accountId; private String username; private String phoneNumber; } 당연히 있어야 하는 계좌번호를 간단하게 accountId라고 나타내고 사용자 명을 username, 그리고 핸드폰 번호를 받는 구조로 구성이 되어있다. 너무나도 당연하게 위 필드들은 모두 Null을 허용하지 않을 생각이다. 비즈니스 관점에서 이 Account라는 도메인의 인스턴스를 활용할 때, 각 필드..