#10 effective java: item 2

This commit is contained in:
haerong22
2022-05-12 01:20:05 +09:00
parent 668c2d69c3
commit e94dea9b6d
4 changed files with 61 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
package com.example.effectivejava.chapter01.item02.freeze;
import java.util.ArrayList;
import java.util.List;
public class Person {
private final String name;
private final int birthYear;
private final List<String> kids;
public Person(String name, int birthYear) {
this.name = name;
this.birthYear = birthYear;
this.kids = new ArrayList<>();
}
public static void main(String[] args) {
}
}

View File

@@ -1,5 +1,7 @@
package com.example.effectivejava.chapter01.item02.hierarchicalbuilder;
import java.util.Objects;
// 코드 2-5 뉴욕 피자 - 계층적 빌더를 활용한 하위 클래스 (20쪽)
public class NyPizza extends Pizza {
public enum Size { SMALL, MEDIUM, LARGE }

View File

@@ -0,0 +1,19 @@
package com.example.effectivejava.chapter01.item02.illegalargumentexception;
import java.time.LocalDate;
public class Order {
public void updateDeliveryDate(LocalDate deliveryDate) {
if (deliveryDate == null) {
throw new NullPointerException("deliveryDate can't be null");
}
if (deliveryDate.isBefore(LocalDate.now())) {
throw new IllegalArgumentException("deliveryDate can't be earlier than " + LocalDate.now());
}
// 배송 날짜 업데이트
}
}

View File

@@ -0,0 +1,17 @@
package com.example.effectivejava.chapter01.item02.varargs;
import java.util.Arrays;
public class VarargsSamples {
public void printNumbers(int... numbers) {
System.out.println(numbers.getClass().getCanonicalName());
System.out.println(numbers.getClass().getComponentType());
Arrays.stream(numbers).forEach(System.out::println);
}
public static void main(String[] args) {
VarargsSamples samples = new VarargsSamples();
samples.printNumbers(1, 20, 20, 39, 59);
}
}