kevinmost
05/26/2016, 2:29 PMLong
or a Date
, I'd do:
var timestamp: Long = 0
fun setTimestamp(date: java.util.Date) {
timestamp = date.getTime()
}
fun main(args: Array<String>) {
val date = java.util.Date()
setTimestamp(date)
println(timestamp)
}
It might be nice to instead do:
var timestamp: Long = 0
set(value: Long) { // Maybe this could be omitted entirely since it's just the default setter behavior
field = value
}
set(value: java.util.Date) {
field = value.getTime()
}
fun main(args: Array<String>) {
val date = java.util.Date()
timestamp = date
println(timestamp)
}
I suppose it might be argued that you shouldn't be in any situations where you find it advantageous to be able to set a property directly like this from any amount of arbitrary types, though?