id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id
title
category
status
canonical_id
aliases
duplicate_of
source_trust_level
confidence_score
verification_status
tags
raw_sources
last_reinforced
github_commit
tech_stack
wiki-2026-0508-generics-and-polymorphism
Generics and Polymorphism
10_Wiki/Topics
verified
self
Parametric Polymorphism
제네릭
none
A
0.9
applied
type-system
generics
polymorphism
2026-05-10
pending
language
framework
typescript
type-system
Generics and Polymorphism
매 한 줄
"매 한 번 작성, 매 여러 type 에 작동" . 매 parametric polymorphism (generics) + ad-hoc polymorphism (overloading / traits) + subtype polymorphism (inheritance) 의 셋이 modern type system 의 backbone. 2026 시점 TS 5.x conditional types, Rust trait + GAT, Go 1.21+ generics 가 매 mainstream.
매 핵심
매 polymorphism 의 종류
Parametric : type parameter <T> — 매 List, Vec, []T.
Ad-hoc : overloading, type classes, traits, interfaces with default impl.
Subtype : 매 Liskov — Cat extends Animal.
Row / Structural : TS object shape, OCaml row polymorphism.
매 dispatch
Static (monomorphization) : Rust, C++ template — 매 compile-time 에 specialize → zero overhead.
Dynamic (vtable) : Java interface, Go interface, Rust dyn Trait — 매 runtime indirection.
매 응용
Collection / container 의 reuse.
Algorithm 의 generic write (sort, map).
API design 의 type-safe abstraction.
Dependency injection 의 decoupling.
💻 패턴
TypeScript — generic constraint
TS — conditional + infer
Rust — trait + generic
Rust — GAT (Generic Associated Type)
Rust — dyn vs impl Trait
Go — generics (1.21+)
Java — bounded wildcard (PECS)
Haskell — type class (ad-hoc)
매 결정 기준
상황
Approach
Container reuse
parametric <T>
Multiple impl 의 한 interface
trait / interface
Hot path, type set 작음
monomorphization (Rust, C++ template)
Heterogeneous collection
dyn Trait / interface{} / Box
Known finite variants
sum type (enum / discriminated union) — 매 generic 보다 simple
기본값 : TS / Java 는 generics + interface, Rust 는 generic + trait (static dispatch).
🔗 Graph
🤖 LLM 활용
언제 : API surface design / type signature 의 reasoning / variance bug 진단.
언제 X : 매 simple concrete type 만 쓰는 곳에 generic 강제 — 매 over-abstraction.
❌ 안티패턴
Generic for one caller : 매 YAGNI — 매 concrete 부터.
Unbounded <T> 의 남용 : 매 actually 필요한 constraint 누락.
Variance 무시 (Java) : List<Cat> 을 List<Animal> 자리에 — covariance bug.
dyn Trait everywhere (Rust) : 매 hot path 에서 vtable cost 누적.
Type erasure 의 망각 (Java) : runtime 에 T 의 reflection 시도.
🧪 검증 / 중복
Verified (Pierce TAPL 2002, Rust Reference, TS Handbook 5.x, Go spec 1.21).
신뢰도 A.
🕓 Changelog
날짜
변경
2026-05-08
Phase 1
2026-05-10
Manual cleanup — TS/Rust/Go/Java generics + polymorphism 종류 정리