Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumSwifttype erasureSingle-choice MCQ

Before `any` existential syntax and the standard `AnyHashable`, the classic hand-rolled type eraser uses an abstract base class plus a generic subclass ("box"). What is the role of the abstract base class in that pattern?

private class _AnyBoxBase<T> { func get() -> T { fatalError() } } private final class _Box<C: Container>: _AnyBoxBase<C.Item> { let concrete: C init(_ c: C) { concrete = c } override func get() -> C.Item { concrete.first } }