seniorKotlin

How does Kotlin handle generics and variance (in/out)?

Updated May 16, 2026

Short answer

Kotlin uses declaration-site variance using in/out keywords.

Deep explanation

Covariance (out) allows a type to be a subtype safely, while contravariance (in) allows supertype substitution. Kotlin enforces variance at compile time to ensure type safety in generics.

Unlock with a Pro subscription to view this section.

View pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More Kotlin interview questions

View all →