Skip to content

Instantly share code, notes, and snippets.

@advancedxy
Created May 1, 2015 22:38
Show Gist options
  • Save advancedxy/08a76fb618a3f804e108 to your computer and use it in GitHub Desktop.
Save advancedxy/08a76fb618a3f804e108 to your computer and use it in GitHub Desktop.
Stackable Trait simulate
trait BeforeAndAfterEach { def beforeEach(): Unit = () }
trait ResetSystemProperties extends BeforeAndAfterEach { override def beforeEach(): Unit = println("reset") }
class A extends BeforeAndAfterEach with ResetSystemProperties { override def beforeEach() { println("test") } }
class B extends BeforeAndAfterEach with ResetSystemProperties { override def beforeEach() { super.beforeEach(); println("test") } }
scala> (new A()).beforeEach
test
scala> (new B()).beforeEach
reset
test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment