Skip to content

Instantly share code, notes, and snippets.

@azami
Created May 8, 2020 06:01
Show Gist options
  • Save azami/9699b5e393389c3fd88e1b5e78f4fa30 to your computer and use it in GitHub Desktop.
Save azami/9699b5e393389c3fd88e1b5e78f4fa30 to your computer and use it in GitHub Desktop.
kotlin pythonの__new__みたいなやつ
open class DayOfTheWeek {
var s = 0
constructor() {
this.s = 0
}
constructor(foo: Int) {
this.s = foo
}
companion object {
operator fun invoke(s: Int): DayOfTheWeek {
return Monday(s)
}
}
class Monday(s: Int) : DayOfTheWeek()
class Tuesday(s: Int) : DayOfTheWeek()
}
fun main() {
println(DayOfTheWeek(234).s)
println(DayOfTheWeek().s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment