Skip to content

Instantly share code, notes, and snippets.

@folarinmartins
Created October 16, 2021 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save folarinmartins/7c88b9107cd5bfc1307574110e54d6ed to your computer and use it in GitHub Desktop.
Save folarinmartins/7c88b9107cd5bfc1307574110e54d6ed to your computer and use it in GitHub Desktop.
Snippets: Introduction to Kotlin
open class Person(var name:String, var age:Int){
open fun appelation():String{
return "Yo!"
}
override fun toString():String{
return "${this.appelation()} $name"
}
fun forceChoke(){
println("You have attempted for the last time Com. ${this.name}")
}
}
class Male(name:String, age:Int, var trouserLength:Int):Person(name,age){
override fun appelation():String{
return "Mr."
}
}
fun main() {
var name : String? = null;
val nameLength = name?.length ?: -1;
var male = Male("Adebayo Sanni",23,32)
println("$male")
println("Hello ${male.appelation()} ${male.name}, ${male.age}yo isn't too old! $nameLength")
val sumA: (Int,Int)->Int = {x,y->x+y}
println(sumA(3,2))
val sumB = {x: Int, y:Int->x+y}
println(sumB(3,3))
male.forceChoke()
fun downloadData(uri:String,completion:((progress:Double)->Unit)){
//make download request
//get data
//call completion with percentage donw
//
for(i in 1..100){
completion(i.toDouble())
}
println("Download is complete")
}
downloadData("https://google.com/myhiddenfile.csv",{perc:Double->println("Current download progress is $perc%")})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment