Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class User(
val name: Name,
val age: Age
)
class Name private constructor(
val value: String
) {
companion object {
fun of(value: String): Name {
require(value.length in (2..25))
return Name(value)
}
}
}
class Age private constructor(
val value: Int
) {
companion object {
fun of(value: Int): Age {
require(value in (0..110))
return Age(value)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment