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

Notes are being added. Planned topics:

TopicDescription
Primitives vs. ObjectsStack vs. heap, null safety, autoboxing/unboxing pitfalls.
Generics<T> syntax, bounded type parameters, generic methods and classes.
Wildcards? extends T (producer), ? super T (consumer), PECS rule.
Type ErasureWhy generics are compile-time only; reflection and instanceof implications.
Type Inferencevar (Java 10+), diamond operator <>, 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.