Recall & Review
beginner
What is a star projection in Kotlin generics?
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?
✗ Incorrect
List<*> means the list holds elements of some unknown type, preserving type safety.
Can you add an element to a List<*> in Kotlin?
✗ 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?
✗ Incorrect
The star (*) symbol is used to represent an unknown generic type in Kotlin.
Why is star projection safer than using raw types?
✗ Incorrect
Star projection keeps the compiler aware of unknown types, preventing unsafe operations.
What is the difference between List<*> and List?
✗ 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.