Java Generics Interview Questions 2026: 26 Q&A With Code

What changed in 2026 drives
Mass-recruiter offer letters are flatter for 2026 batch - the 4-5 LPA ASE band has barely budged in three years while inflation eats real wages. Premium tracks (Digital, Pro, Elite, Specialist) are still where the differential lives, and they are entirely test-driven. If you are aiming higher than the default offer, the coding round is not optional pageantry - it is the entire interview.
What I'd actually study for this
- 01Two solid coding-round answers (1 medium-hard DSA each, with edge-case discussion) > five half-baked ones
- 02One real project you can defend end-to-end - file paths, design decisions, and what you would change
- 03One DBMS schema you actually built (not a textbook ER diagram), with at least 3 join-heavy queries written from memory
- 04Three behavioural STAR stories: failure recovered, conflict handled, ownership taken
Where most candidates trip up
The single biggest mistake is treating company-specific guides as primary prep and DSA as secondary. It is the opposite. Mass recruiters use the test as a filter, but premium tracks at every IT services company use coding to allocate offer band. Spend 70% of prep time on DSA + system fundamentals, 20% on company-specific patterns, 10% on HR rehearsal. Reverse that ratio and you collect the default offer.
Editorial commentary by Aditya Sharma · written for PapersAdda · not generated, not aggregated.
Last Updated: June 2026 | Level: Freshers to Mid-Level | Read Time: ~15 min
Generics are where Java interviews probe whether you understand the type system, not just the syntax. Candidates report that type erasure, wildcards, and the PECS principle are guaranteed for backend and product roles. This guide covers 26 generics questions with full answers and predict-the-output traps. Behaviour reflects the official Oracle Java tutorials; confirm any type-system detail on the JLS.
Pair this with Java Interview Questions 2026 and Java Collections Interview Questions 2026.
Table of Contents
- Fundamentals (Q1 to Q9)
- Type Erasure (Q10 to Q15)
- Wildcards and Bounds (Q16 to Q22)
- Advanced (Q23 to Q26)
- Predict the Output
- Quick Revision Table
- Frequently Asked Questions
Fundamentals
Q1. What are generics in Java? Easy
List<String> names = new ArrayList<>();
names.add("Alice");
String s = names.get(0); // no cast needed
Q2. Why were generics introduced? Easy
Q3. What is a generic class? Medium
class Box<T> {
private T value;
void set(T v) { value = v; }
T get() { return value; }
}
Q4. What is a generic method? Medium
static <T> T firstOf(List<T> list) { return list.get(0); }
Q5. What are the naming conventions for type parameters? Easy
Q6. Can you use primitives as type arguments? Medium
Q7. What is the diamond operator? Easy
Q8. What is a bounded type parameter? Medium
Q9. Can a generic type have multiple bounds? Hard
Type Erasure
Q10. What is type erasure? Hard
Q11. Why can you not use instanceof with a parameterised type? Hard
Q12. Why can you not create a generic array? Hard
Q13. Can two methods differ only by generic type? Hard
Q14. What is a raw type? Medium
Q15. Can you reference a static field of type parameter T? Medium
Wildcards and Bounds
Q16. What is a wildcard in generics? Medium
Q17. What is an upper-bounded wildcard? Medium
double sum(List<? extends Number> nums) {
double s = 0;
for (Number n : nums) s += n.doubleValue();
return s;
}
Q18. What is a lower-bounded wildcard? Medium
Q19. What is the PECS principle? Hard
Q20. What is the difference between List<Object> and List<?>? Hard
Q21. Why can you not add to a List<? extends Number>? Hard
Q22. What is an unbounded wildcard good for? Medium
Advanced
Q23. What is a recursive generic bound? Hard
Q24. Can a generic class extend another generic class? Medium
Q25. What are bridge methods? Hard
Q26. Are generics covariant like arrays? Hard
Predict the Output
Snippet 1
List<Integer> ints = new ArrayList<>();
List<String> strs = new ArrayList<>();
System.out.println(ints.getClass() == strs.getClass());
Output:
true
Why: Type erasure means both are just ArrayList at runtime, so their classes are identical.
Snippet 2
List<? extends Number> list = new ArrayList<Integer>();
// list.add(1); // compile error
Number n = list.get(0);
Output:
(compiles only without the add line)
Why: An upper-bounded wildcard is read-only for the element type; add is rejected, get returns Number.
Snippet 3
static <T> T pick(T a, T b) { return a; }
System.out.println(pick("x", 5).getClass().getSimpleName());
Output:
Object
Why: With mixed arguments the inferred T is the common supertype Object (technically Serializable & Comparable), so the returned reference type is Object-like; the actual object returned is the String "x".
Quick Revision Table
| Concept | Key takeaway |
|---|---|
| generics | compile-time type safety |
| type erasure | no type info at runtime |
| no generic array | erasure prevents it |
| extends wildcard | read (producer) |
| super wildcard | write (consumer) |
| PECS | producer extends, consumer super |
| invariance | List<Integer> not a List<Object> |
Frequently Asked Questions
What generics topic is asked most in Java interviews in 2026?
Candidates report that type erasure, the difference between extends and super wildcards (PECS), and why you cannot create a generic array are the three most repeated Java generics questions.
Is type erasure important for interviews?
Yes. Understanding that generics are a compile-time feature erased at runtime explains many restrictions, like why you cannot use instanceof with a parameterised type or create new T.
What does PECS mean?
Producer Extends, Consumer Super. Use extends when a structure produces values you read, and super when it consumes values you write. It guides correct wildcard use in APIs.
Why are generics invariant when arrays are covariant?
Array covariance defers type checking to runtime and can throw ArrayStoreException, while generic invariance catches the same mismatch at compile time. Wildcards let you opt into controlled variance when you need it.
Why can I not add to a List<? extends Number>?
Because the list might actually be a List<Integer> or List<Double>, and the compiler cannot guarantee the value you add matches the real element type, so it forbids all adds except null.
Related Articles
- Java Interview Questions 2026, the master 50-question set
- Java Collections Interview Questions 2026, generics power collections
- Java OOPs Interview Questions 2026, object model
- Java Output Prediction Questions 2026, tricky snippets
Confirm any type-system detail on the official Oracle Java documentation before your interview. This guide reflects candidate-reported patterns and public preparation resources as of June 2026.
Methodology applied to this articlelast verified 8 Jun 2026
- No fabricated salary numbers or success rates. If we quote a range, it's sourced.
- No noun-substituted templates. This article was not generated by swapping company names in a stock prompt.
- No paid placements, sponsored coaching links, or affiliate-shilled course pushes.
Explore this topic cluster
More resources in Interview Questions
Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.
Paid contributor programme
Sat this this year? Share your story, earn ₹500.
First-person experience reports help future candidates prep smarter. We pay verified contributors ₹500 via UPI per accepted story - with byline.
Submit your story →Ready to practice?
Take a free timed mock test
Put what you learned into practice. Our mock tests match the 2026 pattern with timer, navigator, reveal, and score breakdown. No signup.
Start Free Mock Test →Related Articles
Airbnb Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing Airbnb's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical, behavioural,...
Airtel Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing Airtel's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical, behavioural,...
AMD Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing AMD's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical, behavioural,...
Atlassian Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing Atlassian's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical,...
Barclays Interview Questions 2026
_Last verified by [Aditya Sharma](/author/aditya-sharma/) · cross-checked against PapersAdda Hiring Pulse and...
More from PapersAdda
Accenture Interview Process 2026: Rounds & Prep
Accenture Interview Questions 2026 (with Answers for Freshers)
Adobe Interview Process 2026: Rounds, OA & Aptitude
Amazon Interview Process 2026: Full Loop + Bar Raiser