Skip to content

Instantly share code, notes, and snippets.

@Hoegy
Created May 25, 2021 23:25
Show Gist options
  • Save Hoegy/6b6b4f54958c59f2a19c1953cf8a2a58 to your computer and use it in GitHub Desktop.
Save Hoegy/6b6b4f54958c59f2a19c1953cf8a2a58 to your computer and use it in GitHub Desktop.
open class Vehicle {
var make = ""
var model = ""
}
interface LandVehicle
fun <T> T.cruiseTheBoulevard(): String where T: Vehicle, T: LandVehicle {
return "cruising the boulevard with my $make $model"
}
class Automobile: Vehicle(), LandVehicle
class Rocket: Vehicle()
fun main(args: Array<String>) {
val myCar = Automobile()
myCar.run { make = "Chevrolet"; model = "Bel Air" }
println("Right now I am: ${myCar.cruiseTheBoulevard()}")
val myRocket = Rocket()
myRocket.run { make = "SpaceX"; model = "Starship" }
// println("Right now I am: ${myRocket.cruiseTheBoulevard()}") // Compiler error if not commented out!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment