object Company {
opaque type Name = String
object Name {
def apply(s: String): Name = s
}
extension (name: Name) def length: Int = name.length
// inside: Name <-> String
def fullName(first: Name, second: Name): Name = {
first.concat(second) // String 의 method 를 사용 가능
}
}
@main def Main(): Unit = {
import Company.*
// Outside, Name & String are NOT related
val first: Name = "First" // NOT allowed, Error !!!
val fn: Name = fullName(Name("First"), Name("Second")) // OK
println(fn.length) // 11 extension method 를 통해 String 의 length 만 노출
}