#10 effective java: item 2
This commit is contained in:
@@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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 }
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
// 배송 날짜 업데이트
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user