Repository navigation
Table of Contents
들어가기
객체 생성과 파괴
Item 1: Consider static factory methods instead of constructors
생성자 대신 정적 팩터리 메서드를 고려하라
Item 2: Consider a builder when faced with many constructor parameters
생성자에 매개변수가 많다면 빌더를 고려하라
Item 3: Enforce the singleton property with a private constructor or an enum type
private 생성자나 열거 타입으로 싱글턴임을 보증하라
Item 4: Enforce noninstantiability with a private constructor
private 생성자로 인스턴스화 불가능을 만들어라
Item 5: Prefer dependency injection to hardwiring resources
자원을 직접 명시하지 않고 의존 객체 주입을 사용하라
Item 6: Avoid creating unnecessary objects
불필요한 객체 생성을 피하라
Item 7: Eliminate obsolete object references
사라진 객체 참조를 해제하라
Item 8: Avoid finalizers and cleaners
finalizer와 cleaner 사용을 피하라
Item 9: Prefer try-with-resources to try-finally
try-finally보다는 try-with-resources를 사용하라
모든 객체의 공통 메서드
Item 10: Obey the general contract when overriding equals
equals를 재정의하려거든 일반 규약을 따르라
Item 11: Always override hashCode when you override equals
equals를 재정의할 때는 hashCode도 반드시 재정의하라
Item 12: Always override toString
toString을 항상 재정의하라
Item 13: Override clone judiciously
clone을 신중히 재정의하라
Item 14: Consider implementing Comparable
Comparable을 구현할지 고려하라
클래스와 인터페이스
Item 15: Minimize the accessibility of classes and members
클래스와 멤버의 접근 권한을 최소화하라
Item 16: In public classes, use accessor methods, not public fields
public 클래스에서는 public 필드가 아닌 접근자 메서드를 사용하라
Item 17: Minimize mutability
가변성을 최소화하라
Item 18: Favor composition over inheritance
상속보다는 구성을 활용하라
Item 19: Design and document for inheritance or else prohibit it
상속을 고려하라면 설계와 문서화를 함께 하라. 그렇지 않다면 상속을 금지하라
Item 20: Prefer interfaces to abstract classes
추상 클래스보다는 인터페이스를 우선하라
Item 21: Design interfaces for posterity
후세를 위해 인터페이스를 설계하라
Item 22: Use interfaces only to define types
인터페이스는 타입을 정의하는 용도로만 사용하라
Item 23: Prefer class hierarchies to tagged classes
태그 달린 클래스보다는 클래스 계층구조를 활용하라
Item 24: Favor static member classes over nonstatic
비정적 멤버 클래스보다는 정적 멤버 클래스를 선호하라
제네릭
Item 25: Prefer lists to arrays
배열보다는 리스트를 사용하라
Item 26: Favor generic types
제네릭 타입을 선호하라
Item 27: Favor generic methods
제네릭 메서드를 선호하라
Item 28: Use bounded wildcards to increase API flexibility
API의 유연성을 높이기 위해 한정적 와일드카드를 사용하라
Item 29: Consider typesafe heterogeneous containers
타입 안전 이종 컨테이너를 고려하라
열거 타입과 애너테이션
Item 30: Use enums instead of int constants
int 상수 대신 열거 타입을 사용하라
Item 31: Use instance fields instead of ordinals
ordinal 대신 인스턴스 필드를 사용하라
Item 32: Use EnumSet instead of bit fields
비트 필드 대신 EnumSet을 사용하라
Item 33: Use EnumMap instead of ordinal indexing
ordinal 인덱싱 대신 EnumMap을 사용하라
Item 34: Emulate extensible enums with interfaces
인터페이스를 사용해 확장 가능한 열거 타입을 흉내내라
Item 35: Prefer annotations to naming patterns
이름 패턴보다 애너테이션을 선호하라
Item 36: Consistently use the Override annotation
Override 애너테이션을 일관되게 사용하라
Item 37: Use marker interfaces to define types
타입을 정의하기 위해 마커 인터페이스를 사용하라
람다와 스트림
Item 38: Check parameters for validity
유효성을 검사하는 매개변수들을 확인하라
Item 39: Make defensive copies when needed
필요할 때 방어적 복사를 수행하라
Item 40: Design method signatures carefully
메서드 서명을 신중하게 설계하라
Item 41: Use overloading judiciously
신중하게 오버로딩을 사용하라
Item 42: Use varargs judiciously
신중하게 가변 인수를 사용하라
Item 43: Return empty collections or arrays, not nulls
null이 아닌 빈 컬렉션 또는 배열을 반환하라
Item 44: Write doc comments for all exposed API elements
공개 API 요소에 대해 문서화 주석을 작성하라
8 Methods
메서드
Item 45: Use the functional approach to generate sequences
시퀀스를 생성할 때 함수적 접근 방식을 사용하라
Item 46: Prefer side-effect-free functions in streams
스트림에서는 부작용 없는 함수를 선호하라
Item 47: Prefer Collection to Stream as a return type
반환 타입으로는 Stream보다는 Collection을 선호하라
Item 48: Use caution when making streams parallel
스트림을 병렬로 만들 때 주의하라
9 General Programming
일반 프로그래밍
Item 49: Check parameters for validity
매개변수의 유효성을 검사하라
Item 50: Make defensive copies when needed
필요할 때 방어적 복사를 수행하라
Item 51: Design method signatures carefully
메서드 서명을 신중하게 설계하라
Item 52: Use overloading judiciously
신중하게 오버로딩을 사용하라
Item 53: Use varargs judiciously
신중하게 가변 인수를 사용하라
Item 54: Return empty collections or arrays, not nulls
null이 아닌 빈 컬렉션 또는 배열을 반환하라
Item 55: Return optionals judiciously
신중하게 옵셔널을 반환하라
Item 56: Write doc comments for all exposed API elements
공개 API 요소에 대해 문서화 주석을 작성하라
10 Exceptions
예외
Item 57: Use exceptions only for exceptional conditions
예외적인 상황에만 예외를 사용하라
Item 58: Use checked exceptions for recoverable conditions and runtime exceptions for programming errors
회복 가능한 상황에는 체크된 예외를 사용하고, 프로그래밍 오류에는 런타임 예외를 사용하라
Item 59: Avoid unnecessary use of checked exceptions
불필요한 체크된 예외 사용을 피하라
Item 60: Favor the use of standard exceptions
표준 예외를 사용하라
Item 61: Throw exceptions appropriate to the abstraction
추상화 수준에 맞는 예외를 던져라
Item 62: Document all exceptions thrown by each method
각 메서드가 던지는 모든 예외를 문서화하라
Item 63: Include failure-capture information in detail messages
상세 메시지에 실패 포착 정보를 포함하라
Item 64: Strive for failure atomicity
실패 원자성을 지향하라
Item 65: Don't ignore exceptions
예외를 무시하지 마라
11 Concurrency
동시성
Item 66: Synchronize access to shared mutable data
공유된 가변 데이터에 대한 접근을 동기화하라
Item 67: Avoid excessive synchronization
과도한 동기화는 피하라
Item 68: Prefer executors, tasks, and streams to threads
스레드보다는 실행자, 태스크, 스트림을 선호하라
Item 69: Prefer concurrency utilities to wait and notify
wait와 notify보다는 동시성 유틸리티를 사용하라
Item 70: Document thread safety
스레드 안전성을 문서화하라
Item 71: Use lazy initialization judiciously
게으른 초기화를 신중하게 사용하라
Item 72: Don't depend on the thread scheduler
스레드 스케줄러에 의존하지 마라
Item 73: Avoid thread groups
스레드 그룹을 사용하지 마라
12 Serialization
직렬화
Item 74: Implement Serializable with great caution
Serializable을 구현할 때는 매우 신중하라
Item 75: Consider using a custom serialized form
사용자 정의 직렬화 형태를 고려하라
Item 76: Read object defensively
객체를 방어적으로 읽어라
Item 77: For instance control, prefer enum types to readResolve
인스턴스 제어에는 readResolve보다 열거 타입을 선호하라
Item 78: Consider serialization proxies instead of serialized instances
직렬화된 인스턴스 대신 직렬화 프록시를 고려하라
13 Concurrency (continued)
동시성 (계속)
Item 79: Avoid excessive synchronization
과도한 동기화 피하기
Item 80: Prefer executors and tasks to threads
실행자(executors)와 태스크(tasks)를 스레드에 우선하라
Item 81: Prefer concurrency utilities to wait and notify
wait와 notify보다 동시성 유틸리티를 선호하라
Item 82: Document thread safety
스레드 안전성 문서화하기
Item 83: Use lazy initialization judiciously
게으른 초기화를 신중하게 사용하라
14 Serialization
직렬화
Item 84: Implement Serializable judiciously
신중하게 Serializable 구현하기
Item 85: Prefer alternatives to Java serialization
Java 직렬화의 대안을 선호하라
Item 86: Implement Serializable with great caution
큰 주의를 기울여 Serializable 구현하기
Item 87: Consider using a custom serialized form
사용자 정의 직렬화 형태를 고려하라
Item 88: Write readObject methods defensively
방어적으로 readObject 메서드 작성하기
Item 89: For instance control, prefer enum type to readResolve
인스턴스 제어에는 readResolve보다 열거 타입을 선호하라
Item 90: Consider serialization proxies instead of serialized instances
직렬화된 인스턴스 대신 직렬화 프록시를 고려하라