Simpler approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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