``` data class Foo( val bar : Baz ) data class ...
# getting-started
d
Copy code
data class Foo(
   val bar : Baz
)
data class Baz(
   val smth : String
   val zzz : String?
)
How would I enforce
zzz
not to be null in Foo (and in Foo only)? Can I achieve a non-nullable
zzz
there?
d
Copy code
data class Foo(
    val bar : Baz<String>
)
data class Baz<T : String?>(
    val smth : String,
    val zzz : T
)
👍 3
d
Copy code
data class Foo(
   override val bar : Baz
) : InterfaceWithBarFromLibrary
data class BazFromLibrary(
   val smth : String
   val zzz : String?
)
Thanks for the answer, Take. I guess my example was too minimal for my usecase
I guess I could not do something like that here, especially as Baz is in a library
d
Ah, yes if it's in a library you cannot do it.
n
i think you could make a inline class copy of Baz, that replaces zzz to be non nullable and a method to get a actual baz