// *** before: ***
inline class OldPassword(val value: String) // an experimental inline class
// *** in version 1.5: ***
@JvmInline
value class Password(private val value: String) {
init {
require(value.length >= 8) { "the password is too short" }
}
fun masked() = "*".repeat(value.length)
}
@JvmInline
value class Meters(val amount: Double) {
operator fun plus(other: Meters) = Meters(amount + other.amount)
}
fun main() {
// no wrapper object is created at run time, the String itself is passed
println(Password("secret42").masked())
println((Meters(1.5) + Meters(2.0)).amount)
}