rook
06/04/2018, 4:13 PMDate
classzucen.co
06/04/2018, 4:28 PMthis
referenco for the original date and can not do lambda right?Andreas Sinz
06/04/2018, 4:31 PMzucen.co
06/04/2018, 4:33 PMfun Date.add(calendarUnit: Int, amount:Int): Date = let{
val calendar = java.util.Calendar.getInstance()
calendar.time=this
calendar.add(calendarUnit,amount)
return calendar.time
}
Andreas Sinz
06/04/2018, 4:40 PMlet
, the date is both this
and it
, but its fine like thatzucen.co
06/04/2018, 4:48 PMthis
.. but i liked to get callendar into lambda as it
but i probably overcomplicate ...rook
06/04/2018, 5:05 PMfun Date.add(calendarUnit: Int, amount: Int) {
return java.util.Calendar.getInstance().apply{
time = this
add(calendarUnit, amount)
}.time
}
rook
06/04/2018, 5:05 PMzucen.co
06/04/2018, 5:15 PMzucen.co
06/04/2018, 5:16 PMfun Date.add(calendarUnit: Int, amount:Int): Date = let{
val calendar = java.util.Calendar.getInstance()
calendar.time=this
calendar.add(calendarUnit,amount)
return calendar.time
}
rook
06/04/2018, 5:20 PMlet
isn’t giving you any special functionality there. It’s essentially taking up space. You’re not even invoking it
, which is the default binding it provides. You can just remove the = let
and it functions precisely the same.zucen.co
06/05/2018, 8:22 AMfun Date.add(calendarUnit: Int, amount:Int):Date =
Calendar.getInstance().let {
it.time=this
it.add(calendarUnit,amount)
it.time
}