Jack Englund
08/24/2019, 12:45 AMfun System.currentTimeSeconds(): Long {
return System.currentTimeMillis()/1000
}
and yet I can't do System.currentTimeSeconds(). Am I missing a concept or can you not do extension functions on System?Dominaezzz
08/24/2019, 12:58 AMSystem().currentTimeSeconds()
fun System.Companion.currentTimeSeconds(): Long {
return System.currentTimeMillis()/1000
}
System
doesn't define a companion object, since it's Java nd stuff.Jack Englund
08/24/2019, 1:09 AMSystem()...
doesn't work because <init> is private.
Why does the example used here:
https://kotlinlang.org/docs/reference/extensions.html
not create an instance?SiebelsTim
08/24/2019, 6:59 AMLuca Nicoletti
08/24/2019, 7:44 AMinstance
of the class you’re extendingAlowaniak
08/24/2019, 11:23 AMJack Englund
08/25/2019, 3:18 AMLuca Nicoletti
08/25/2019, 5:48 AMval list = mutableListOf(1, 2, 3)
list.swap(0, 2) // 'this' inside 'swap()' will hold the value of 'list'
That’s exactly what we said, the swap
function is called on an instance