Java Type System
Java's type system is the rules the compiler uses to verify program correctness at compile time. Understanding the boundary between primitives and objects, how generics achieve type safety without runtime overhead (type erasure), and how
varinfers types are all recurring interview topics and common sources of subtle bugs.
What You'll Find Here
| Topic | Description |
|---|---|
| Primitives vs. Objects | Stack vs. heap, null safety, autoboxing/unboxing pitfalls, the Integer cache. |
| Generics | <T> syntax, bounded type parameters, generic methods, classes, and interfaces. |
| Wildcards | ? extends T (producer), ? super T (consumer), PECS rule, unbounded <?>. |
| Type Erasure | Why generics are compile-time only; bridge methods, heap pollution, super type tokens. |
| Type Inference | var (Java 10+), diamond operator <>, generic method inference, lambda target typing. |
Learning Path
- Primitives vs. Objects — autoboxing bugs are a frequent interview trap; start here.
- Generics — learn
<T>syntax before wildcards; bounded type parameters build on plain generics. - Wildcards — the PECS rule (
extends= producer,super= consumer) is consistently misunderstood. - Type Erasure — once generics are clear, understand WHY the JVM can't hold
List<String>.classat runtime. - Type Inference —
varand the diamond operator are syntactic sugar; understand their constraints.
Related Domains
- Core Java — primitive types and type conversion are the foundation.
- Collections Framework — generics define the entire collections API.
- Functional Programming — lambda type inference is a key application of generic wildcards.