Created
May 8, 2020 06:01
-
-
Save azami/9699b5e393389c3fd88e1b5e78f4fa30 to your computer and use it in GitHub Desktop.
kotlin pythonの__new__みたいなやつ
This file contains hidden or 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
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