Last active
January 4, 2017 20:41
-
-
Save drdozer/4c28be747e9f05af347c8f482d130e74 to your computer and use it in GitHub Desktop.
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
import scala.reflect.ClassTag | |
trait MyCollection[T] | |
{ | |
def ping(c2: MyCollection[T]): Unit | |
def pong[C1 <: MyCollection[T] : ClassTag](c1: C1): Unit | |
def pung[C1 <: MyCollection[T], C2 <: MyCollection[T]](c1: C1, c2: C2)(implicit C1: ClassTag[C1], C2: ClassTag[C2]): Unit | |
} | |
class AListyCollection[T] extends MyCollection[T] | |
{ | |
def ping(c2: MyCollection[T]): Unit = c2.pong(this) | |
def pong[C1 <: MyCollection[T] : ClassTag](c1: C1): Unit = c1.pung(c1, this) | |
def pung[C1 <: MyCollection[T], C2 <: MyCollection[T]](c1: C1, c2: C2)(implicit C1: ClassTag[C1], C2: ClassTag[C2]): Unit = | |
println(s"Pingpong at $C1, $C2") | |
} | |
class ASettyCollection[T] extends MyCollection[T] | |
{ | |
def ping(c2: MyCollection[T]): Unit = c2.pong(this) | |
def pong[C1 <: MyCollection[T] : ClassTag](c1: C1): Unit = c1.pung(c1, this) | |
def pung[C1 <: MyCollection[T], C2 <: MyCollection[T]](c1: C1, c2: C2)(implicit C1: ClassTag[C1], C2: ClassTag[C2]): Unit = | |
println(s"Pingpong at $C1, $C2") | |
} | |
val l1 = new AListyCollection[String] | |
val l2 = new AListyCollection[String] | |
val s1 = new ASettyCollection[String] | |
val s2 = new ASettyCollection[String] | |
l1.ping(l2) | |
s1.ping(s2) | |
l1.ping(s2) | |
s1.ping(l2) | |
(l1: MyCollection[String]).ping(s2 : MyCollection[String]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Produces:
Pingpong at $file.appending$AListyCollection, $file.appending$AListyCollection
Pingpong at $file.appending$ASettyCollection, $file.appending$ASettyCollection
Pingpong at $file.appending$ASettyCollection, $file.appending$AListyCollection
Pingpong at $file.appending$AListyCollection, $file.appending$ASettyCollection
Pingpong at $file.appending$AListyCollection, $file.appending$ASettyCollection