A star projection is a way to say "I don't know the exact type" for a generic parameter. It uses the * symbol to represent an unknown type safely.
Click to reveal answer
beginner
How do you write a star projection for a generic type List in Kotlin?
You write it as List<*> which means a list of some unknown type.
Click to reveal answer
intermediate
Why use star projection instead of a raw type in Kotlin?
Star projection keeps type safety by acknowledging unknown types, while raw types can cause unsafe operations and errors.
Click to reveal answer
intermediate
What is the difference between List<*> and List in Kotlin?
List<*> means a list of some unknown type, while List means a list that can hold any type including null. The first is safer for reading unknown types.
Click to reveal answer
beginner
Can you add elements to a List<*> in Kotlin?
No, you cannot add elements to a List<*> because the exact type is unknown, so adding could break type safety.
Click to reveal answer
What does List<*> mean in Kotlin?
AA list with an unknown element type
BA list of Any type elements
CA list that can only hold null
DA list with no elements
✗ Incorrect
List<*> means the list holds elements of some unknown type, preserving type safety.
Can you add an element to a List<*> in Kotlin?
ANo, because the element type is unknown
BYes, any element can be added
COnly null can be added
DOnly elements of type Any can be added
✗ Incorrect
You cannot add elements to List<*> because Kotlin does not know the exact type, so adding could cause errors.
Which symbol is used for star projection in Kotlin generics?
A&
B?
C#
D*
✗ Incorrect
The star (*) symbol is used to represent an unknown generic type in Kotlin.
Why is star projection safer than using raw types?
ABecause it allows adding any type
BBecause it converts all types to Any
CBecause it preserves type safety by acknowledging unknown types
DBecause it disables generics
✗ Incorrect
Star projection keeps the compiler aware of unknown types, preventing unsafe operations.
What is the difference between List<*> and List?
AList<*> can hold any type; List<Any?> is unknown
BList<*> is unknown type; List<Any?> can hold any type including null
CBoth are exactly the same
DList<*> can only hold null; List<Any?> cannot
✗ Incorrect
List<*> means unknown element type; List means elements can be any type or null.
Explain what star projection means in Kotlin generics and why it is useful.
Think about how Kotlin handles unknown generic types safely.
You got /4 concepts.
Describe the difference between List<*> and List in Kotlin and when you might use each.
Consider what each means for the types of elements allowed.
You got /4 concepts.
Practice
(1/5)
1. What does the star projection * represent in Kotlin generics?
easy
A. A type that can only be used with primitive data types
B. A specific generic type that must be defined explicitly
C. A wildcard that allows writing but restricts reading
D. An unknown generic type that allows safe reading but restricts writing
Solution
Step 1: Understand star projection meaning
The star projection * means an unknown generic type in Kotlin.
Step 2: Analyze its usage
It allows safe reading from generic collections but restricts writing to avoid type errors.
Final Answer:
An unknown generic type that allows safe reading but restricts writing -> Option D
Quick Check:
Star projection = unknown generic type with safe read [OK]
Hint: Star projection means unknown type, safe read only [OK]
Common Mistakes:
Thinking star projection allows writing to generics
Confusing star projection with specific generic types
Assuming star projection only works with primitives
2. Which of the following is the correct syntax to declare a list with star projection in Kotlin?
easy
A. val list: List<Any> = listOf(1, 2, 3)
B. val list: List<*> = listOf(1, 2, 3)
C. val list: List<> = listOf(1, 2, 3)
D. val list: List = listOf(1, 2, 3)
Solution
Step 1: Recall star projection syntax
Star projection uses * inside angle brackets to represent unknown type.
Step 2: Check each option
val list: List<*> = listOf(1, 2, 3) uses List<*> which is correct syntax for star projection.