Skip to content

Instantly share code, notes, and snippets.

@humblerookie

humblerookie/Vehicle.kt Secret

Last active Jul 19, 2020
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
You can’t perform that action at this time.