Skip to content

Instantly share code, notes, and snippets.

@humblerookie
Last active July 19, 2020 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save humblerookie/8b63a87020c51e96cc57fd62be818fa3 to your computer and use it in GitHub Desktop.
Save humblerookie/8b63a87020c51e96cc57fd62be818fa3 to your computer and use it in GitHub Desktop.
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