Skip to main content

How do wildcards in generics work?

Junior Java
Quick Answer Wildcards represent unknown types in generics. ? (unbounded): accepts any type - useful for reading. ? extends T (upper bounded): accepts T or subtypes - can read as T, can't write. ? super T (lower bounded): accepts T or supertypes - can write T, reading gives Object. Remember PECS: Producer Extends (read-only), Consumer Super (write-only).

Answer

? extends T: Accepts T or subclasses.
? super T: Accepts T or superclasses.
Used for flexible yet safe type handling.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice