Question
When should a Java developer choose Generics and Wildcards deliberately?
- Choose Generics and Wildcards mainly when you want to postpone validation and fix problems manually later.
- Choose Generics and Wildcards whenever you want the code to look more advanced, even if the design gets less clear.
- Choose Generics and Wildcards only to avoid modeling domain rules explicitly in Java code.
- Use generics on APIs when you want callers and implementers to see the type contract clearly at compile time.
Hint
Think about the production scenario where the choice genuinely improves the code.
Answer and rationale
Correct answer: D. Use generics on APIs when you want callers and implementers to see the type contract clearly at compile time.
Use generics on APIs when you want callers and implementers to see the type contract clearly at compile time. Interviewers often ask this to see whether you can connect the concept to real design decisions.
Track: Java