Skip to content

Instantly share code, notes, and snippets.

@humblerookie
Last active July 19, 2020 14:09
Embed
What would you like to do?
Simpler approach
class Vehicle(var type: VehicleType = CYCLE) {
@Deprecated("Use constructor with 'type' info instead")
constructor (isCar: Boolean) : this(if (isCar) CAR else CYCLE)
@Deprecated("Use 'type', instead", ReplaceWith("type"))
var isCar: Boolean = false
get() = type == CAR
set(value) {
field = value
type = if (value) CAR else CYCLE
}
enum class VehicleType {
CYCLE, CAR, TRUCK, SHIP
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment