Imagine you have created a MailBox class, and it can accept all types of parameters. Also you've created a class Letter. Your friend added a type bound, and MailBox now accepts only CherryPie, which is not what you need! It would make more sense to restrict type bounds so that MailBox can accept only Letter and its descendants as parameters. Correct the provided code.
Type Bounds
Checking mailbox
Report a typo
Write a program in Kotlin
// don't change Letter and CherryPie!
class Letter
class CherryPie
// correct the code
class MailBox<T : CherryPie>(var value: T) {
fun sendLetter() {
println("Letter is sent!")
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.