제네릭 메서드
-
이펙티브 자바 : 제네릭 클래스와 제네릭 메서드책책책 책을 읽읍시다/프로그래밍 2023. 7. 7. 22:57
제네릭 클래스 아래와 같은 비(非)제네릭 스택 클래스가 있다고 해보자. public class Stack { private Object[] elements; private int size = 0; private static final int DEFAULT_INITIAL_CAPACITY = 16; public Stack() { elements = new Object[DEFAULT_INITIAL_CAPACITY]; } public void push(Object e) { ensureCapacity(); elements[size++] = e; } public Object pop() { if (size == 0) throw new EmptyStackException(); Object result = element..