Questions: Generics and Template Specialization

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A Rust program calls a generic sort function with 15 different concrete types. A Java program calls a generic sort function with the same 15 types. How do the compiled outputs differ?

ABoth produce 15 specialized copies — Rust and Java both use monomorphization
BRust produces 15 specialized copies; Java produces one shared version using type erasure
CJava produces 15 specialized copies; Rust produces one shared version via dictionary passing
DBoth produce a single shared version — modern compilers always prefer smaller binaries
Question 2 Multiple Choice

What is the core performance advantage of monomorphization over type erasure?

AMonomorphization allows faster compilation because types are resolved earlier
BMonomorphization produces type-specific code that the optimizer can inline, vectorize, and constant-fold without indirection
CMonomorphization eliminates the need for garbage collection, reducing runtime overhead
DMonomorphization shares code between instantiations, reducing instruction cache pressure
Question 3 True / False

Type erasure is typically slower than monomorphization because it discards most type information, leaving the runtime unable to perform any type-specific optimizations.

TTrue
FFalse
Question 4 True / False

In a language that uses type erasure for generics, a List<Integer> and a List<String> share the same compiled bytecode at runtime.

TTrue
FFalse
Question 5 Short Answer

Explain the core tradeoff between monomorphization and type erasure in terms of runtime performance and binary size.

Think about your answer, then reveal below.