Last active
January 5, 2018 15:12
-
-
Save kahneraja/d1078f95ee09091018a18afa372f1794 to your computer and use it in GitHub Desktop.
Exploring Interfaces in Scala
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
trait Vehicle { | |
def drive = { | |
println("drive vehicle") | |
} | |
} | |
trait Boat extends Vehicle { | |
override def drive = println("drive boat!") | |
} | |
trait Plane extends Vehicle { | |
override def drive = println("drive plane!") | |
} | |
trait MockPlane extends Vehicle { | |
override def drive = println("let's mock this!") | |
} | |
class Seaplane extends Plane with Boat { | |
} | |
val s = new Seaplane | |
s.drive | |
val testS = new Seaplane with MockPlane | |
testS.drive | |
// #TraitLinerization. Runs the last "with" trait. In this case it will "drive boat". |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exploring Super Interfaces in Java 8.
https://gist.github.com/kahneraja/4199a2ccb621a7e15842a4d64a9d4f38