Created
May 25, 2021 23:25
-
-
Save Hoegy/6b6b4f54958c59f2a19c1953cf8a2a58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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