Skip to content

Instantly share code, notes, and snippets.

@amir343
Created October 12, 2011 08:02
Show Gist options
  • Save amir343/1280571 to your computer and use it in GitHub Desktop.
Save amir343/1280571 to your computer and use it in GitHub Desktop.
Source that is used for Scala Type Variances blog posts series
class BufferControl {
def control(channel:NetworkChannel[String]) {
}
}
class AnyRefChannel extends NetworkChannel[AnyRef] {
override def write(x:AnyRef) {
}
}
class StringChannel extends NetworkChannel[String] {
override def write(x:String) {
}
}
class Company[+T](val company:T)
class Company[T](val company:T)
class BigCompany
class SmallCompany extends BigCompany
class Investor(val company: Company[BigCompany])
class CrappyCompany
trait Function1[-S, +T] {
def apply(x:S): T
}
trait NetworkChannel[-T] {
def write(x: T)
}
class Company[+T](val company:T) {
def partnerWith[U >: T](y: U) {
}
}
// This won't compile
class Company[+T](val company:T) {
def partnerWith(y: T) {
}
}
class Company[+T](val company:T) {
def partnerWith[U <: Company[BigCompany]](y: U) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment