Skip to content

Instantly share code, notes, and snippets.

@igstan
Created April 4, 2014 11:38
Show Gist options
  • Save igstan/9972776 to your computer and use it in GitHub Desktop.
Save igstan/9972776 to your computer and use it in GitHub Desktop.
Scala lower bounds + multiple argument list.
class Sup
class Sub(val element: Int) extends Sup
def test1[B >: Sub](a: Sub, b: B): B = if (a.element < 0) b else a
// ||
// || difference
// ||
// \/
def test2[B >: Sub](a: Sub)(b: B): B = if (a.element < 0) b else a
test1(new Sub(1), new Sub(1)) // res17: Sub = Sub@37e5f771
test2(new Sub(1))(new Sub(1)) // res18: Sub = Sub@37900029
test1(new Sub(1), new Sup) // res19: Sup = Sub@2fa357c9
test2(new Sub(1))(new Sup) // WTF?!
// <console>:11: error: type mismatch;
// found : Sup
// required: Sub
// test2(new Sub(1))(new Sup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment