【发布时间】:2017-06-03 18:57:42
【问题描述】:
嘿,我想在 kotlin 中创建一个类,它将包含我将在几个地方使用的所有扩展函数,例如:
class DateUtils {
//in this case I use jodatime
fun Long.toDateTime() : DateTime = DateTime(this)
fun String.toDateTime() : DateTime = DateTime.parse(this)
}
class SomeClassWithNoConnectionToDateUtils {
fun handleDataFromServer(startDate: String) {
someOtherFunction()
//startDate knows about toDateTime function in DateUtils
startDate.toDateTime().plusDays(4)
}
}
有没有办法进行这样的操作
【问题讨论】: