Skip to main content

Java Type System Interview Questions

Concise Q&A covering primitives vs. reference types, autoboxing pitfalls, generics, wildcards, and type erasure.

Beginner

Q: What is autoboxing?
A: Automatic conversion between primitives and their wrapper types (e.g., intInteger). Watch out for == vs equals() when comparing wrappers.

Intermediate

Q: Why do generics use type erasure in Java?
A: To preserve backward compatibility with older JVMs and bytecode; generic type information isn't available at runtime, so operations requiring runtime type checks are limited.

Advanced

Q: Explain PECS (Producer Extends, Consumer Super).
A: Use ? extends T when you only read (produce) T from a structure; use ? super T when you only write (consume) T into a structure.