<T>
<T extends Car>
Los parámetros genéricos no están disponibles en tiempo de ejecución, son solo para el tiempo de compilación. Esto significa que no puedes hacer algo como esto:
class Executor<T, U> {
public execute(executable: T): void {
if (T instanceof Executable1) { // Compilation error
...
} else if (U instanceof Executable2){ // Compilation error
...
}
}
}
Sin embargo, la información de la clase aún se conserva, por lo que aún puede probar el tipo de variable como siempre ha podido:
class Executor<T, U> {
public execute(executable: T): void {
if (executable instanceof Executable1) {
...
} else if (executable instanceof Executable2){
...
} // But in this method, since there is no parameter of type `U` it is non-sensical to ask about U's "type"
}
}