You have your own small kitchen. As an engineer, you have discovered that classes for devices Microwave, MultiCooker implement the interfaces Logger (with a log() method) and Cooker (with a cook() method). For further engineering, you need to complete a generic class SmartKitchen that takes only the types which implement both Cooker and Logger. Complete its method finishCooking(), which takes allowed device and invokes log().
Type Bounds
Cooking and coding are fine!
Report a typo
Write a program in Kotlin
// change the code below
class SmartKitchen<T> {
fun finishCooking() {
// finish the method
}
}
// don't change it!
interface Logger { fun log() }
interface Cooker { fun cook() }
class Microwave : Logger, Cooker {
override fun log() = println("Microwave finished cooking!")
override fun cook() = println("Microwave is cooking")
}
class MultiCooker : Logger, Cooker {
override fun log() = println("Multicooker finished cooking!")
override fun cook() = println("Multicooker is cooking")
}
___
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.