Conceptcore
Type erasure
Also called erasure, reified generics, reification.
Type erasure removes type information when a program is compiled. Reification keeps it for the run time. Java and TypeScript erase type arguments, and C# and Go keep them.
- Applies to
- core-languages
Idea
A compiler knows the type of each expression. The question is how much of that knowledge the running program keeps. Type erasure removes it. The compiler checks the types, and then it emits code that has no record of some of them. Reification keeps it. A reified type is one that the running program can see, test and pass around.
Most languages keep some types and erase others. A Java object knows its class, but not the type arguments of its class. The JLS calls the types that keep all their information at run time reifiable types.2 A C# object knows its class and its type arguments.1213 A TypeScript program keeps no static types at all, because the compiler removes every type annotation.25
The Java program below asks two questions. The first asks for the declared type of the field names. The second asks the object in the field for its type parameter.
import java.util.ArrayList;
import java.util.List;
public class Main {
static List<String> names = new ArrayList<>();
public static void main(String[] args) throws Exception {
System.out.println(Main.class.getDeclaredField("names").getGenericType());
System.out.println(names.getClass().getTypeParameters()[0]);
}
}
java.util.List<java.lang.String>
E
The declaration keeps its full type, because the compiler writes it into the Signature attribute of the class file. The virtual machine does not use this attribute to check anything, but reflection can read it.5 The object knows only its class ArrayList and the name E of its type parameter. It has no record of String. Generics describes the ways to compile generic code. This page is about what each way leaves for the run time.
How it works
Erasure in Java. The JLS defines type erasure as a mapping from types to types that are never parameterized types or type variables. The erasure of List<String> is List. The erasure of a type variable is the erasure of its leftmost bound, so T becomes Object and T extends Comparable<T> becomes Comparable.1 The compiler checks the program with the full types. Then it compiles each generic class once, with the erased types. This follows GJ, the design that Java generics came from. The GJ translation erases all type parameters, maps type variables to their bounds, and inserts casts where they are needed.30
A reifiable type keeps all its information at run time. The reifiable types are primitive types, types that are not generic, and raw types. Parameterized types whose type arguments are all unbounded wildcards, such as List<?>, are reifiable too. So are arrays of these types.2 Some operations need the type at run time, so Java rejects them for a type that is not reifiable:
- An array creation, such as
new T[n]ornew List<String>[n], is a compile-time error.9 - A class literal, such as
T.class, is a compile-time error.10 new T()does not compile, andinstanceof ArrayList<Integer>does not compile, because the run time does not know the type argument.11- Two methods of one class with the same name must have different erasures. So
total(List<Integer>)andtotal(List<String>)cannot both exist.8
A raw type, such as List with no type arguments, exists only for compatibility with code that was written before generics.3 Through a raw type or an unchecked cast, a variable of a parameterized type can refer to an object that is not of that type. The JLS calls this heap pollution. The run time cannot detect it, because type variables are not reified.4
Bridge methods. Erasure can change the signature of a method that implements another method. A class that implements Comparator<String> declares compare(String, String). After erasure, the method of the interface is compare(Object, Object). So the compiler adds a bridge method with the erased signature. The bridge method casts its arguments and calls the real method.6 The class file marks it with the flag ACC_BRIDGE.7
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Comparator;
public class Main {
static class ByLength implements Comparator<String> {
public int compare(String a, String b) {
return a.length() - b.length();
}
}
public static void main(String[] args) {
Method[] methods = ByLength.class.getDeclaredMethods();
Arrays.sort(methods, Comparator.comparing(Method::toString));
for (Method m : methods) {
System.out.println(Arrays.toString(m.getParameterTypes()) + " bridge=" + m.isBridge());
}
}
}
[class java.lang.Object, class java.lang.Object] bridge=true
[class java.lang.String, class java.lang.String] bridge=false
Reification in C#. The compiled code of a C# generic type holds metadata for its type parameters. At run time, .NET makes one specialized type for each value type that is used as a type argument. All reference types share one specialized type, because all references have the same size.12 Each closed type, such as List<int> or List<string>, is a separate type at run time, and reflection can read its type arguments.13 So the code of a generic method can use typeof(T) and default(T).15 With the constraint where T : new(), it can also call new T().14 Kennedy and Syme designed this support for the .NET Common Language Runtime. Their design gives exact run-time types, specializes code in the just-in-time compiler, and shares code between instantiations that have the same representation.16
Monomorphization in C++ and Rust. A C++ template is a pattern for code. The standard calls the step that makes code from it template instantiation. A function that the compiler makes from a function template is an instantiated function.20 Rust compiles generic code in the same way. The compiler finds each concrete type that generic code is called with, and it makes code for that type. The Rust Book calls this monomorphization.17 Each copy knows its types when it is compiled, so the run time needs no record of them. In the Rust example, type_name::<T>() gives a different name in each copy.
Dictionaries in Go. Go compiles generic code with GC shape stenciling and dictionaries. Two types have the same GC shape when they have the same underlying type, or when both are pointer types. The compiler makes one copy of a generic function for each GC shape. Each call passes a dictionary as a hidden first argument. The dictionary holds the run-time type descriptor of each type argument. The code uses these descriptors for conversions to interfaces, for type assertions and for type switches.24 So a Go type argument is reified. In the Go example, float64 and a named type Celsius share one copy of the code, and reflection still tells them apart.
Erasure of all types. The TypeScript compiler checks the types and then removes them, so the annotations never change what the program does.25 A type assertion, such as value as number, is removed too. It has no check at run time, so a wrong assertion causes no exception and no null.26 Python keeps annotations as data, but the interpreter does not enforce them.28 A generic alias such as list[int] keeps its type argument in __args__. An object that is made from the alias is a plain list, so the type argument is erased when the object is created. isinstance does not accept a parameterized generic.27
| Language | What the run time has | Can code read T at run time? |
|---|---|---|
| Java, Kotlin | one copy of the code with erased types129 | no; pass a Class<T> token |
| TypeScript | no types at all25 | no; pass a function that checks a value |
| Python | annotations as data, not checked27 | the alias keeps T; the object does not |
| C# | type arguments in each closed type13 | yes, with typeof(T) |
| Go | one copy for each GC shape, and a dictionary24 | yes, through the dictionary |
| C++, Rust | one copy for each set of type arguments2017 | each copy knows T when it is compiled |
In languages
| Language | Verdict | Note |
|---|---|---|
| Python | Native | |
| C++ | Native | |
| Java | Native | |
| C | Absent | ISO C has no type parameters and keeps no type information at run time; a void * does not record the type of the object that it points to. Alternative: A struct with a tag field that names the type of its payload. |
| C# | Native | |
| JavaScript | Does not apply | JavaScript has no static types, so the compiler has nothing to erase; each value carries its own type at run time. Alternative: Typeof and instanceof test the type of a value at run time. |
| TypeScript | Native | |
| Go | Native | |
| Rust | Native | |
| Kotlin | Native | Kotlin erases type arguments on the JVM, as Java does, and an inline function can declare a reified type parameter that is known at each call site; no example file because kotlinc is not installed on the machine that recorded the examples. |
| SQL | Does not apply | A query has no generic types and no type arguments. |
| Bash | Does not apply | Bash has no static types, so there is nothing to erase. |
| PowerShell | Standard library | PowerShell uses the generic types of .NET, and the .NET runtime keeps their type arguments; no example file because pwsh is not installed on the machine that recorded the examples. |
| HTML | Does not apply | Markup has no types. |
| CSS | Does not apply | Style rules have no types. |
| Regular expressions | Does not apply | A pattern has no types. |
The example files show what each language keeps at run time. The table gives the verdict for each tier 1 language.
| Language | Verdict | Form |
|---|---|---|
| Python | native | annotations kept as data and not checked; __args__ on a generic alias27 |
| JavaScript | n/a | no static types; each value carries its type at run time |
| TypeScript | native | all types erased; as has no check at run time26 |
| Java | native | type arguments erased; bridge methods; Class<T> tokens |
| C | absent | no type parameters; no type information at run time |
| C++ | native | each template instantiation is separate code; std::function and std::any hide a type |
| C# | native | type arguments reified; typeof(T), default(T), new T() |
| Go | native | GC shape stenciling with dictionaries; reflection sees T |
| Rust | native | monomorphization; dyn Trait hides the concrete type |
| Kotlin | native | erased on the JVM; reified type parameters in inline functions29 |
| PowerShell | stdlib | the generic types of .NET, which keep their type arguments3412 |
| Bash | n/a | no static types |
| SQL | n/a | no generic types |
| Regex | n/a | a pattern has no types |
| HTML/CSS | n/a | markup and style rules have no types |
Kotlin erases type arguments, as Java does. At run time, an instance of Foo<Bar> is only a Foo<*>, and the compiler rejects a check such as ints is List<Int>. An inline function can declare a reified type parameter. The compiler then inlines the actual type argument at each call site, so value is T works inside that function.29
def first(items: list[int]) -> int:
return items[0]
alias = list[int]
print(alias.__origin__, alias.__args__)
items = alias(["not", "ints"])
print(type(items), first(items))
print(first.__annotations__)
try:
isinstance(items, list[int])
except TypeError as error:
print("TypeError:", error)
<class 'list'> (<class 'int'>,)
<class 'list'> not
{'items': list[int], 'return': <class 'int'>}
TypeError: isinstance() argument 2 cannot be a parameterized generic
- Verdict: native. The interpreter keeps annotations as data, but it does not check them.
list[int]is a generic alias. It keeps its type argument in__args__.- An object made from
list[int]is a plainlist. It has no record ofint, and its elements are not checked. isinstancerefuses a parameterized generic and raisesTypeError.
#include <any>
#include <functional>
#include <print>
#include <string>
#include <typeinfo>
#include <vector>
template <typename T>
std::size_t size_of_one(const T&) {
return sizeof(T);
}
int main() {
std::println("{} {}", size_of_one('a'), size_of_one(1.0));
int factor = 3;
std::vector<std::function<int(int)>> steps;
steps.push_back([](int x) { return x + 1; });
steps.push_back([factor](int x) { return x * factor; });
int value = 2;
for (const auto& step : steps) {
value = step(value);
}
std::println("{}", value);
std::any box = std::string("text");
std::println("{}", box.type() == typeid(std::string));
try {
std::println("{}", std::any_cast<int>(box));
} catch (const std::bad_any_cast&) {
std::println("bad_any_cast");
}
}
1 8
9
true
bad_any_cast
- Verdict: native. Each use of a template with other template arguments is a separate instantiation, so
size_of_one<char>andsize_of_one<double>are two functions. std::function<int(int)>holds any callable object with that call signature. The two lambdas have different types, but the vector holds them as one type. C++ programmers call this technique type erasure.std::anykeeps a value of any type and remembers its type.any_castwith the wrong type throwsstd::bad_any_cast.
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
public class Main {
static <T> T create(Class<T> type) throws Exception {
return type.getDeclaredConstructor().newInstance();
}
abstract static class TypeRef<T> {
final Type type;
TypeRef() {
ParameterizedType parent = (ParameterizedType) getClass().getGenericSuperclass();
type = parent.getActualTypeArguments()[0];
}
}
public static void main(String[] args) throws Exception {
StringBuilder text = create(StringBuilder.class);
text.append("made from a Class token");
System.out.println(text);
Type type = new TypeRef<Map<String, List<Integer>>>() {}.type;
System.out.println(type);
}
}
made from a Class token
java.util.Map<java.lang.String, java.util.List<java.lang.Integer>>
- Verdict: native. The compiler erases type arguments, so an object does not know the type arguments that it was created with.
- A
Class<T>argument is a type token. It carries the type to the run time, socreatecan make an object of that type. new TypeRef<...>() {}declares an anonymous subclass. Its class file records the type argument of its superclass, andgetGenericSuperclassreads it back. This is a super type token.- The type token works only for a type that is written in the source. Inside a generic method,
new TypeRef<T>() {}records only the type variableT.
static T Make<T>() where T : new() => new T();
static string Describe<T>(T value) =>
$"{typeof(T).Name}, default {default(T)?.ToString() ?? "null"}";
static bool IsListOf<T>(object value) => value is List<T>;
Console.WriteLine(Describe(42));
Console.WriteLine(Describe("text"));
Console.WriteLine(Make<List<int>>().GetType());
object names = new List<string> { "Ada" };
Console.WriteLine(IsListOf<string>(names));
Console.WriteLine(IsListOf<int>(names));
Int32, default 0
String, default null
System.Collections.Generic.List`1[System.Int32]
True
False
- Verdict: native. Type arguments are a part of the run-time type. A
List<string>and aList<int>are different types. typeof(T)gives the type argument inside the generic method, anddefault(T)gives the default value of that type.- The constraint
where T : new()lets the body callnew T(). The type argument must have a public constructor with no parameters. value is List<T>tests the type argument at run time. Java rejects the same test at compile time.
class Box<T> {
value: T;
constructor(value: T) {
this.value = value;
}
}
function isBoxOf<T>(value: unknown, check: (x: unknown) => x is T): value is Box<T> {
return value instanceof Box && check(value.value);
}
const isString = (x: unknown): x is string => typeof x === "string";
const a: unknown = new Box("text");
const b: unknown = new Box(42);
console.log(a instanceof Box, b instanceof Box);
console.log(isBoxOf(a, isString), isBoxOf(b, isString));
true true
true false
- Verdict: native. The compiler removes all types, so the JavaScript that runs has no
T. - A class is also a value, so
instanceof Boxworks at run time. The test cannot see the type argument, so both boxes pass it. - To check a type argument, pass a function that checks a value, such as the type guard
isString. - This runner strips the types and does not type-check, so a type error here does not stop the run.
package main
import (
"fmt"
"reflect"
)
type Celsius float64
func describe[T any](value T) string {
switch any(value).(type) {
case int:
return "an int"
case string:
return "a string"
}
return "a " + reflect.TypeOf(value).String()
}
func name[T any]() string {
return reflect.TypeFor[T]().String()
}
func main() {
fmt.Println(describe(42))
fmt.Println(describe("hi"))
fmt.Println(describe(21.5))
fmt.Println(describe(Celsius(21.5)))
fmt.Println(name[[]Celsius](), name[error]())
}
an int
a string
a float64
a main.Celsius
[]main.Celsius error
- Verdict: native. A generic function knows its type arguments at run time. The compiler passes them in a dictionary.
float64andCelsiushave the same underlying type, so they share one compiled copy ofdescribe. The dictionary still tells the two types apart.reflect.TypeFor[T]()gives the type argument with no value at all, even for an interface type such aserror.
use std::any::type_name;
use std::fmt::Display;
use std::mem::size_of;
fn show_static<T: Display>(value: T) -> String {
format!("{} as {}", value, type_name::<T>())
}
fn show_dynamic(value: &dyn Display) -> String {
format!("{}", value)
}
fn main() {
println!("{}", show_static(7u8));
println!("{}", show_static(1.5f32));
let items: Vec<Box<dyn Display>> = vec![Box::new(7u8), Box::new("seven")];
for item in &items {
println!("{}", show_dynamic(item.as_ref()));
}
println!("{} {}", size_of::<&u8>(), size_of::<&dyn Display>());
}
7 as u8
1.5 as f32
7
seven
8 16
- Verdict: native. The compiler monomorphizes generic code, so each copy of
show_staticknows itsT, andtype_namereports it. dyn Displayhides the concrete type. A&dyn Displayis a pointer to the value and a pointer to a vtable. On this 64-bit machine, it is twice the size of a plain reference.- A vector of
Box<dyn Display>holds values of different types. A call through it goes through the vtable.
Variations and related ideas
- Type tokens. A Java method that needs its type at run time can take a
Class<T>argument. The Java Tutorial uses this to create an object of a type parameter with reflection.11 A super type token is an anonymous subclass of a generic class, such asnew TypeRef<Map<String, Integer>>() {}. The class file records the type argument of the superclass in its Signature attribute, andgetGenericSuperclassreads it back.5 The Java example shows both. - Type erasure as a C++ technique. In C++ the term has a second meaning.
std::functionstores, copies and calls any callable object with a given call signature.21std::anyholds one value of any type.22 The concrete type is hidden behind one interface, but the value still knows its type.any_castwith the wrong type throwsstd::bad_any_cast.23 The C++ example shows both. Higher-order function usesstd::functionto pass functions as values. - Trait objects. A Rust
&dyn Displayhides its concrete type in the same way. It is a pointer to the value and a pointer to a vtable, which holds the methods for the concrete type. A call through it is a virtual call.18 Interfaces compares this with the interfaces of other languages. - Run-time types in dynamic languages. In JavaScript and Python, each value carries its type at run time. An operation checks the type when it runs. Static and dynamic typing describes this.
- Casts. A cast to an erased type checks only the erased part, or nothing at all in TypeScript. Type conversion covers the kinds of casts and what each one checks.
Pitfalls
Two overloads clash after erasure
Two methods with the same name must have different erasures.8 Both methods below have the erasure total(List).
This code does not compile, on purpose.
import java.util.List;
public class Main {
static int total(List<Integer> numbers) {
int sum = 0;
for (int n : numbers) {
sum += n;
}
return sum;
}
static int total(List<String> words) {
int sum = 0;
for (String w : words) {
sum += w.length();
}
return sum;
}
public static void main(String[] args) {
System.out.println(total(List.of(1, 2, 3)));
}
}
javac reports name clash: total(List<String>) and total(List<Integer>) have the same erasure. The fix is two names, such as sumOf and totalLength.11
An unchecked cast fails far from its cause
A cast to a type with a type argument checks only the erased type. Here read casts an Object to List<T>, and the run time checks only that the object is a List.
This code raises ClassCastException, on purpose.
import java.util.List;
import java.util.Map;
public class Main {
@SuppressWarnings("unchecked")
static <T> List<T> read(Map<String, Object> config, String key) {
return (List<T>) config.get(key);
}
static int longest(List<String> names) {
int max = 0;
for (String name : names) {
max = Math.max(max, name.length());
}
return max;
}
public static void main(String[] args) {
Map<String, Object> config = Map.of("names", List.of(1, 2, 3));
List<String> names = read(config, "names");
System.out.println("read " + names.size() + " names");
System.out.println(longest(names));
}
}
The program prints read 3 names. The ClassCastException comes later, from the loop in longest, where the compiler inserted a cast to String. The list of numbers is heap pollution: a List<String> variable refers to an object that is not a List<String>.4 The annotation @SuppressWarnings("unchecked") hid the only warning. The fix is a Class<T> token, so that read checks each element when it reads the data.
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Main {
static <T> List<T> read(Map<String, Object> config, String key, Class<T> type) {
List<T> result = new ArrayList<>();
for (Object item : (List<?>) config.get(key)) {
if (!type.isInstance(item)) {
throw new IllegalArgumentException(key + " holds a " + item.getClass().getSimpleName());
}
result.add(type.cast(item));
}
return result;
}
public static void main(String[] args) {
Map<String, Object> config = Map.of("names", List.of(1, 2, 3));
try {
List<String> names = read(config, "names", String.class);
System.out.println(names);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
}
names holds a Integer
A generic array cannot be created
An array knows its element type at run time, but a type variable is not reifiable. So array creation with the element type T is a compile-time error.9
This code does not compile, on purpose.
import java.util.Arrays;
public class Main {
static <T> T[] repeat(T value, int count) {
T[] items = new T[count];
Arrays.fill(items, value);
return items;
}
public static void main(String[] args) {
System.out.println(Arrays.toString(repeat("hi", 3)));
}
}
javac reports generic array creation. The fix passes a Class<T> token, and Array.newInstance makes an array of that class. The cast to T[] is unchecked, but it is correct, because the array has the right class.
import java.lang.reflect.Array;
import java.util.Arrays;
public class Main {
static <T> T[] repeat(Class<T> type, T value, int count) {
@SuppressWarnings("unchecked")
T[] items = (T[]) Array.newInstance(type, count);
Arrays.fill(items, value);
return items;
}
public static void main(String[] args) {
String[] words = repeat(String.class, "hi", 3);
System.out.println(Arrays.toString(words));
System.out.println(words.getClass().getSimpleName());
}
}
[hi, hi, hi]
String[]
C# keeps type arguments at run time, so the code that Java rejects in this section works there.12 new T[count] creates an array, the two Total overloads have different signatures, and is List<string> tests the type argument.
Console.WriteLine(string.Join(" ", Tools.Repeat("hi", 3)));
Console.WriteLine(Tools.Total(new List<int> { 1, 2, 3 }));
Console.WriteLine(Tools.Total(new List<string> { "ab", "cde" }));
object value = new List<int> { 1 };
Console.WriteLine(value is List<string>);
static class Tools
{
public static T[] Repeat<T>(T value, int count)
{
var items = new T[count];
Array.Fill(items, value);
return items;
}
public static int Total(List<int> numbers) => numbers.Sum();
public static int Total(List<string> words) => words.Sum(w => w.Length);
}
hi hi hi
6
5
False
A TypeScript assertion does not check
A type assertion with as tells the compiler to trust the programmer. The compiler removes it, and nothing checks it at run time.26
This code runs but gives a wrong answer on purpose.
function readCount(raw: unknown): number {
return raw as number;
}
const count = readCount("5");
console.log(count + 1);
51
The type of count is number, but its value is the string "5". So + joins two strings, and the program prints 51. The fix is a check at run time with typeof, which also narrows the type for the compiler.
function readCount(raw: unknown): number {
if (typeof raw === "number") {
return raw;
}
if (typeof raw === "string" && /^\d+$/.test(raw)) {
return Number(raw);
}
throw new TypeError(`not a count: ${String(raw)}`);
}
console.log(readCount("5") + 1);
console.log(readCount(5) + 1);
6
6
Cost
- Erasure. One copy of the code serves all type arguments. The price is paid in checks and in boxing. A Java type argument cannot be a primitive type, so a
List<Integer>holdsIntegerobjects.11 A call through a bridge method is one more call with a cast.6 The GJ page states that code translated by erasure is as efficient as Java code written for the same purpose.31 - Reification in .NET. The runtime makes one copy of the code for each value type that is a type argument. All reference types share one copy.12
- Monomorphization. Generic code runs as fast as code for the concrete types, because the compiler makes a copy for each type.17 The price is paid at build time and in the size of the program.
- Trait objects. A call through a
dyn Traitfinds its method at run time. The lookup has a cost, and the compiler cannot inline the method.19 - Dictionaries in Go. One copy of the code serves each GC shape. Each call passes a dictionary as a hidden argument.24
History
- 1998. Gilad Bracha, Martin Odersky, David Stoutamire and Philip Wadler described GJ, an extension of Java with generic types. GJ is translated by erasure, so no information about type parameters is kept at run time.3031
- 1999. In May 1999, Sun proposed to add generics to Java, based on GJ.31
- 2001. Andrew Kennedy and Don Syme described generics for the .NET Common Language Runtime, with exact run-time types.16
- 2004. JSR 14, "Add Generic Types To The Java Programming Language", reached its final release on 30 September 2004.32
- 2022. Go 1.18, released on 15 March 2022, added generics. Its implementation uses GC shape stenciling and dictionaries.3324
References
- The Java Language Specification, Java SE 25 Edition, 4.6 Type Erasure
- The Java Language Specification, Java SE 25 Edition, 4.7 Reifiable Types
- The Java Language Specification, Java SE 25 Edition, 4.8 Raw Types
- The Java Language Specification, Java SE 25 Edition, 4.12.2 Variables of Reference Type (heap pollution)
- The Java Virtual Machine Specification, Java SE 25 Edition, 4.7.9 The Signature Attribute
- The Java Language Specification, Java SE 25 Edition, 15.12.4.5 Create Frame, Synchronize, Transfer Control (the example of a bridge method)
- The Java Virtual Machine Specification, Java SE 25 Edition, 4.6 Methods (the flag ACC_BRIDGE)
- The Java Language Specification, Java SE 25 Edition, 8.4.8.3 Requirements in Overriding and Hiding (methods with the same name must have different erasures)
- The Java Language Specification, Java SE 25 Edition, 15.10.1 Array Creation Expressions
- The Java Language Specification, Java SE 25 Edition, 15.8.2 Class Literals
- The Java Tutorials, Restrictions on Generics, Cannot Instantiate Generic Types with Primitive Types, Cannot Create Instances of Type Parameters, Cannot Use Casts or instanceof with Parameterized Types, Cannot Overload a Method Where the Formal Parameter Types of Each Overload Erase to the Same Raw Type
- C# programming guide, Generics in the runtime, the introduction, value types as type arguments, reference types as type arguments
- C# programming guide, Generics and reflection, the introduction (the runtime has generic type information at run time)
- C# programming guide, Constraints on type parameters, the table of constraints (where T new())
- C# language reference, default value expressions, default operator
- Andrew Kennedy and Don Syme, Design and implementation of generics for the .NET Common Language Runtime, PLDI 2001, the abstract (exact run-time types, just-in-time type specialization, code sharing based on representation)
- The Rust Programming Language, 10.1 Generic Data Types, Performance of Code Using Generics
- The Rust Reference, Trait objects, r-type.trait-object.unsized (a pointer to a trait object holds a pointer to the value and a pointer to a vtable)
- The Rust Programming Language, 18.2 Using Trait Objects to Abstract over Shared Behavior, Performing Dynamic Dispatch
- Working Draft, Programming Languages, C++ (N4950, the C++23 draft), [temp.spec.general], paragraphs 1 and 2
- Working Draft, Programming Languages, C++ (N4950, the C++23 draft), [func.wrap.func], paragraph 1
- Working Draft, Programming Languages, C++ (N4950, the C++23 draft), [any.class], paragraph 1
- Working Draft, Programming Languages, C++ (N4950, the C++23 draft), [any.nonmembers], the Throws clause of any_cast
- Go 1.18 Implementation of Generics via Dictionaries and Gcshape Stenciling, the overview, Gcshapes and Dictionary Format
- TypeScript Handbook, The Basics, Erased Types
- TypeScript Handbook, Everyday Types, Type Assertions
- The Python Standard Library, Built-in Types, Python 3.14, Generic Alias Type (isinstance, the note that the runtime does not enforce annotations, erasure during object creation) and __args__
- The Python Standard Library, typing, Python 3.14, the note at the top of the page
- Kotlin documentation, Generics, in, out, where, Type erasure and Generics type checks and casts (reified type parameters of inline functions)
- Gilad Bracha, Martin Odersky, David Stoutamire and Philip Wadler, Making the future safe for the past, Adding genericity to the Java programming language, OOPSLA 1998, the abstract (the translation erases type parameters, maps type variables to their bounds and inserts casts)
- Philip Wadler, GJ, A Generic Java Language Extension, the timeline at the top of the page and the paragraph Efficient translation
- JSR 14: Add Generic Types To The Java Programming Language, the description and the Final Release date (30 Sep 2004)
- Go release history, go1.18 (released 2022-03-15)
- PowerShell documentation, about_Calling_Generic_Methods, Short description and Long description
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag TRTN8M Edit this page History Report an error Markdown