Burkhard
11/24/2019, 9:36 AM<?>
). Than you could do something like this
data class Test<?>(
val foo: Foo<?>, // nullable depending on class parameter
val bar: Bar, // never null
val baz: Baz:? // allways nullable
)
val test1 = Test<?>(getFooOrNull(), Bar(), null)
val test2 = Test<!>(Foo(), Bar(), null)
test1.foo?.doSomething()
test2.foo.doSomething()
This could be used to easily create Builder classes for data classes with immutable values.class Foo<?SomeName, ?SomeOhterName>
kioba
11/25/2019, 11:45 AMKy Leggiero
11/26/2019, 11:46 PMdata class Test
's generic parameter restricted to implementers of CharSequence
Burkhard
11/27/2019, 3:49 PMTest
to extend CharSequence
? This special generic parameter can only be !
or ?
. If you want to mix this with a normal generic type you could do use class Foo<?, T: CharSequence>
kioba
11/27/2019, 3:55 PMclass Foo<?, T: CharSequence>
is the same saying class `Foo<`Option<>`, CharSequence>`
and
class Foo<!, T: CharSequence>
is the same saying class `Foo<`Id<>`, CharSequence>`Burkhard
11/27/2019, 3:56 PMKy Leggiero
11/28/2019, 12:06 AMT
or something). However, here you just use ?
. How do you reference this without confusing it with the nullability symbol? Can your Test
have multiple ?
parameters? If so, how do you distinguish which is which?Burkhard
11/28/2019, 1:47 AM?
would probably not work. This could lead to multiple issues. I guess they will have to be named and than they could maybe all start with a ?
. Not sure yet.