본문 바로가기

개발/자바12

Java Stream.max() 사용법 일단 Stream.max() 를 공식문서에서 확인해보자. Comparator의 구현체가 파라메터로 전달되어야 한다. 일단 max()를 적용하려는 객체에 객체들간의 순서를 지정할 수 있는 Comparable 인터페이스를 구현하겠다. public class RacingCar implements Comparable { private static final int DEFAULT_POSITION = 0; private int position = DEFAULT_POSITION; // 중간 생략 @Override public int compareTo(RacingCar anotherCar) { return this.position - anotherCar.position; } } compareTo()에 대한 설명을 잠깐.. 2022. 2. 14.
Comparable의 compareTo() 파헤치기 공식문서 파헤치기 Comparable 인터페이스에는 compareTo() 라는 메소드가 존재한다. 오늘은 이것에 대해 공부할 것 이다. Description (설명) : Compares this object with the specified object for order. 현재 객체와 특정 객체를 비교하여 순서를 지정한다. Method Detail을 보자! Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. 현재 객체와.. 2022. 2. 14.
JUnit 사용법 JUnit 이란? Java에서 사용할 수 있는 대표적인 테스트 프레임 워크이다. 다른 언어에서 사용할 수 있는 테스트 프레임워크들도 있는데, 보통 (언어의 약자)Unit 이라고 불리운다. ex ) CUnit, CppUnit, PHPUnit, PyUnit Gradle Dependency dependencies { testImplementation 'org.assertj:assertj-core:3.22.0' testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2' } 자주 사용하는 JUnit Method assertThat - isTrue(), isFalse() true, false 값을 확인할 때 @Test @DisplayName("assertThat으로 t.. 2022. 2. 11.
[Java] clone()에 대해서 목차 - Shallow Copy과 Deep Copy란? - Shallow Cloning - Deep Cloning - ( 번외 ) 배열의 Clone 1. Shallow Copy과 Deep Copy란? Shallow Copy (얕은 복사) : 원본 객체를 복사하여 새롭게 생성하지만 원본 객체 내의 참조자료유형 변수는 원본 객체가 가지고 있는 객체 변수와 동일하다. (기본자료유형에 대해선 deepcopy가 이루어진다.) Deep Copy (깊은 복사) : 원복 객체를 복사하는 것 뿐만 아니라, 원본 객체 내의 객체 변수들 까지도 완벽히 복사된다. Shallow Copy 그림설명 Deep Copy 그림 설명 2. Shallow Copy Java에서 객체에 대한 Clone() 메소드를 사용하려면 Clonable.. 2021. 5. 17.