Created
July 27, 2013 03:29
-
-
Save notyy/6093587 to your computer and use it in GitHub Desktop.
this implicit works for scala
This file contains hidden or 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
package com.github.notyy.retroboard.util | |
import org.scalatest.FunSpec | |
import org.scalatest.matchers.ShouldMatchers | |
trait Base { | |
protected def getChildren: List[String] | |
} | |
object Base { | |
implicit class SBase[T <: Base](child: T) { | |
def apply = child.getChildren | |
} | |
} | |
class Child1 extends Base { | |
protected def getChildren: List[String] = List("child1") | |
} | |
class Child2 extends Base { | |
def getChildren: List[String] = List("child2") | |
} | |
class InheritenceSpec extends FunSpec with ShouldMatchers { | |
describe("SBase") { | |
it("should add apply method to all children of Base") { | |
println(new Child1().apply) | |
println(new Child2().apply) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment