Created
November 16, 2010 12:52
-
-
Save fff/701793 to your computer and use it in GitHub Desktop.
why generic failed?
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
class Banana | |
object Monkey { | |
def eat(bananas: Seq[Banana]) = println("lots of banana") | |
def eat(banana: Banana) = println("one banana") | |
} | |
object Person { | |
def pickBanana = new Banana | |
def pickBananas = List(new Banana, new Banana) | |
} | |
object FeedMonkey { | |
def feed[T](food: => T, eat: T => Unit): Unit = eat(food) | |
def main(args: Array[String]) { | |
//below lines are failed | |
/* error:ambiguous reference to overloaded definition, both method eat in object Monkey of | |
type (banana: Banana)Unit and method eat in object Monkey of type (bananas: Seq[Banana])Unit match expected | |
type (?) => Unit */ | |
feed(Person.pickBanana, Monkey.eat) | |
feed(Person.pickBananas, Monkey.eat) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment