You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fun Instant?.truncateToSeconds(): Instant? =
this?.truncatedTo(ChronoUnit.SECONDS)
TO-BE
fun Instant.truncateToSeconds(): Instant =
this.truncatedTo(ChronoUnit.SECONDS)
MOTIVATION
Receiving a nullable Instant instance in this case is almost useless. Since Kotlin natively supports nullsafe operator(?.), invoking truncateToSeconds via null safe call still conserve nullity of receiving object. For non-null cases, however, this call converts receiving instance as 'maybe' type and it adds a mandatory, cumbersome non-null assertion operator(!!) which degrades code readibility.
IMPACT
truncateToSeconds calls on nullable instance will not compile after this fix.
The text was updated successfully, but these errors were encountered:
FrancescoJo
changed the title
Fix truncateToSeconds extension signature to receive non-null only
Fix truncateToSeconds extension function signature to receive non-null only
Feb 22, 2022
AS-IS
TO-BE
MOTIVATION
Receiving a nullable
Instant
instance in this case is almost useless. Since Kotlin natively supports nullsafe operator(?.
), invokingtruncateToSeconds
via null safe call still conserve nullity of receiving object. For non-null cases, however, this call converts receiving instance as 'maybe' type and it adds a mandatory, cumbersome non-null assertion operator(!!
) which degrades code readibility.IMPACT
truncateToSeconds
calls on nullable instance will not compile after this fix.The text was updated successfully, but these errors were encountered: