Skip to content

Instantly share code, notes, and snippets.

@hiramekun
Created July 10, 2020 09:28
Show Gist options
  • Save hiramekun/441cea1381b5e88f4e201b4609035e2f to your computer and use it in GitHub Desktop.
Save hiramekun/441cea1381b5e88f4e201b4609035e2f to your computer and use it in GitHub Desktop.
反変、共変周りの練習
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