You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
도입
제네릭 기반
Stack
으로 탈바꿈하기Before
Object
기반Stack
코드를 통해 #15 에서 확인했던Stack
소스 코드는 다음과 같다.Stack.java
After
여기서 제네릭을 도입한
Stack
소스 코드는 다음과 같다.Stack.java
실체화 불가 타입으로 배열을 사용할 때
적절한 해결책
elements
필드의 타입을E[]
에서Object[]
로 바꾸는 방법타입 매개변수에 제약을 두는 제네릭 타입
java.util.concurrent.DelayQueue
처럼 타입 매개변수에 제약을 두는 제네릭 타입도 있다.DelayQueue.java
정리
Stack
자료구조에서 아쉬운 부분이 있다면 바로 필드 중 하나인elements
의 타입이다.elements
의 타입은Object
인데, 이렇게 되면 client-side 에서 직접 형 변환을 해줘야 하는 책임을 가진다.@SuppressWarnings
애노테이션으로 해당 경고를 숨긴다.Beta Was this translation helpful? Give feedback.
All reactions