ursus
12/30/2025, 8:19 PMexplicit backing fields
interface VersionChecker {
val supportedVersion: Flow<Boolean>
}
class VersionCheckerImpl(
...
) : VersionChecker {
override val supportedVersion: Flow<Boolean>
field = MutableStateFlow(true)
...
}
and this fails to compile with Properties with explicit backing fields must be final.
Which granted is true, but - is really this the desired outcome? In a production app, it's most likely that this will be the pattern (exposed via interface), rendering the feature kinda uselessŠimon Kručinin
12/30/2025, 9:14 PMprivate val mutableSupportedVersion = MutableStateFlow(true)
override val supportedVersion: Flow<Boolean>
get() = mutableSupportedVersion
override val supportedVersion: Flow<Boolean> = MutableStateFlow(true)
field is useful for local transformation during assignment or validation, but there are other ways, too. This is probably the easiest though.ursus
12/30/2025, 10:35 PMŠimon Kručinin
12/31/2025, 11:55 AMŠimon Kručinin
12/31/2025, 12:04 PMfinal override, can’t you?
In many cases, you don’t need to extend the implementation class further, just to implement the interface. The feature would still be useful in these scenarios.ursus
12/31/2025, 12:20 PM