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
fun main() { | |
downloadTasks( | |
object : DownloadCallback { | |
override fun onDownloaded(tasks: List<Task>) { | |
printTasks(tasks) | |
} | |
} | |
) | |
} | |
interface DownloadCallback { | |
fun onDownloaded(tasks: List<Task>) | |
} | |
private fun downloadTasks(callback: DownloadCallback) { | |
println("Downloading...") | |
// code that makes a network call and returns the list of tasks | |
callback.onDownloaded(listOf(Task(1), Task(2), Task(3))) | |
} | |
private fun printTasks(tasks: List<Task>) { | |
tasks.forEach { task -> println(task.id) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment