Card 09/ 09
All 9 cards
RecapDifficulty: Advanced1 min
What the Compiler Knows, and What the Runtime Forgot
Five things this topic established, and where each one was.
| The thing | Where |
|---|---|
| A type parameter moves a failure from the reading line to the writing line | Moving a Cast From the Moment It Runs |
Type arguments are erased, so List<String> is a List at runtime | What Is Left of List<String> |
A List<String> is not a List<Object>, because adding would corrupt it | Why a List<String> Is Not a List<Object> |
Producer extends, consumer super — the wildcard states the direction | extends and super |
new T[], new T(), instanceof T and T.class are all refused | Why You Cannot Write new T[] |
The one worth carrying: every awkward rule in this topic is erasure. The compiler knows the type argument and the runtime does not, so anything needing the type while running is refused, and anything the compiler can check is checked early.