Using value class wrapping reference type is good ...
# getting-started
u
Using value class wrapping reference type is good choice?
Copy code
@JvmInline
value class Men(val human: Human) {
    /** men specific functions */
}

@JvmInline
value class Woman(val human: Human) {
    /** women specific functions */
}
The reason why i wrapped human by Men or Women is Human has so lots of properties that i want to devide
j
I see no value in doing that over the normal interfaces Man and Woman
1
I might be wrong, but i think the man reason of value class is to create different types from the same underlying type. It's great if we are talking about primitives or strings, but i see no value with reference types
s
if you have control over the Human class you should use normal inheritance, e.g.
Copy code
sealed class Human(
    // comman properties
){
   class Man(...): Human(...) {...}
    class Woman(....): Human(...) {...}
    class Other(....): Human(...) {...}

  // common methods
}
If you don't maybe construct a Wrapper hierachy in this way. The main problem in your current approach is that the classes Man and Woman share no common superclass apart from Any (which is to broad). And a function expection Human couldn't be provided with an instance of Man or Woman (even though JavaInline value classes are (mostly) compiled away).
1
👀 1