Checking mailbox

Report a typo

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.

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!")
}
}
___

Create a free account to access the full topic