Created
April 4, 2014 11:38
-
-
Save igstan/9972776 to your computer and use it in GitHub Desktop.
Scala lower bounds + multiple argument list.
This file contains 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
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