Created
July 10, 2020 09:28
-
-
Save hiramekun/441cea1381b5e88f4e201b4609035e2f to your computer and use it in GitHub Desktop.
反変、共変周りの練習
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 Publication(val title: String) | |
class Book(title: String) extends Publication(title) | |
object Library { | |
val books: Set[Book] = Set(new Book("Programming in Scala"), new Book("Walden")) | |
def printBookList(info: Book => AnyRef) = { | |
for (book <- books) println(info(book)) | |
} | |
} | |
object Customer extends App { | |
def getTitle(p: Publication): String = p.title | |
Library.printBookList(getTitle) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment