I have a Kotlin helper class defined as:
class CountdownTimer(endDateInSeconds: Long, callback: (timeRemaining: RemainingTime) -> Unit)
which, as the name implies, takes an era time and a callback to call at fixed intervals (in this case seconds) until the end date is reached. RemainingTime is a data class containing the amount of time (seconds, minutes, hours, etc.) until the end date.
I can use this class from Kotlin purely:
countdownTimer = CountdownTimer(endDate, { timeRemaining ->
var timeString =
view?.updateCountdownTimer(timeString)
})
However, when I call this from Java, I am forced to provide an unnecessary return value in the callback, despite the fact that the anonymous function indicates the type of the returned module (which is theoretically equivalent to the return type of Java void):
this.countdownTimer = new CountdownTimer(this.endDate, remainingTime -> {
var timeString =
if (view != null) {
view.updateCountdownTimer(timeString);
}
return null;
});
, Java .. . ?