Skip to main content

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 var infers types are all recurring interview topics and common sources of subtle bugs.

What You'll Find Here

TopicDescription
Primitives vs. ObjectsStack 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 ErasureWhy generics are compile-time only; bridge methods, heap pollution, super type tokens.
Type Inferencevar (Java 10+), diamond operator <>, generic method inference, lambda target typing.

Learning Path

  1. Primitives vs. Objects — autoboxing bugs are a frequent interview trap; start here.
  2. Generics — learn <T> syntax before wildcards; bounded type parameters build on plain generics.
  3. Wildcards — the PECS rule (extends = producer, super = consumer) is consistently misunderstood.
  4. Type Erasure — once generics are clear, understand WHY the JVM can't hold List<String>.class at runtime.
  5. Type Inferencevar and the diamond operator are syntactic sugar; understand their constraints.