jw
04/04/2018, 2:09 PMfun isWeekend(date: Date): Boolean
mplacona
04/04/2018, 2:17 PMclass ExtensionFunctions{
fun Date.isWeekend() = day == 6 || day == 7
}
I won't be able to test it by just calling isWeekend(Date())
on the class right?diesieben07
04/04/2018, 2:19 PMDate.isWeekend
is both an extension function of Date
and a member function of ExtensionFunctions
, so you need both receivers in scope.
In a member-function of ExtensionFunctions
you can just call Date().isWeekend()
, outside you would need
with (instanceOfExtensionFunctions) {
Date().isWeekend()
}
mplacona
04/04/2018, 2:23 PMdiesieben07
04/04/2018, 2:24 PMmplacona
04/04/2018, 2:26 PMimport java.util.*
fun main(args: Array<String>) {
fun Date.isWeekend() = day == 6 || day == 7
}
diesieben07
04/04/2018, 2:26 PMmplacona
04/04/2018, 2:27 PM