https://kotlinlang.org logo
Title
d

dG

02/13/2019, 10:41 AM
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

diesieben07

02/13/2019, 10:45 AM
data class Foo(
    val bar : Baz<String>
)
data class Baz<T : String?>(
    val smth : String,
    val zzz : T
)
👍 3
d

dG

02/13/2019, 10:47 AM
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

diesieben07

02/13/2019, 10:47 AM
Ah, yes if it's in a library you cannot do it.
n

Nikky

02/15/2019, 7:59 AM
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