I have java code like this:
public class IntervalHolder
{
public final Interval last24Hrs;
public IntervalHolder()
{
DateTime now = DateTime.now().minuteOfHour().roundFloorCopy();
DateTime oneDayAgo = now.minusHours(24);
last24Hrs = new Interval(oneDayAgo, now);
}
}
How do I express this in Kotlin?
The best I could come up with is this:
class IntervalHolder
{
lateinit var last24Hrs: Interval;
constructor()
{
val now = DateTime.now().minuteOfHour().roundFloorCopy()
val oneDayAgo = now.minusHours(24)
last24Hrs = Interval(oneDayAgo, now)
}
}
but now last24Hrs
is a mutable property instead of being immutable like in the java code.