Sam Garfinkel
03/31/2020, 5:55 PMval foo: String? by defaultProperty { null }
? It only goes away by explicitly defining the type of defaultProperty<String?>
LastExceed
03/31/2020, 5:57 PMSam Garfinkel
03/31/2020, 5:58 PMdiesieben07
03/31/2020, 6:00 PMnull
is inferred to be of type Nothing?
here, so defaultProperty { null }
is a ReadWriteProperty<Any?, Nothing?>
. If you only want a val
you should use ReadOnlyProperty
, which has its type parameter marked out
, in that scenario your code should compile.Sam Garfinkel
03/31/2020, 6:03 PMReadWriteProperty
’s generics?diesieben07
03/31/2020, 6:04 PMdiesieben07
03/31/2020, 6:05 PMReadWriteProperty
then you have to specify the type, otherwise there is no way for the compiler to know that you want a String?
there.Sam Garfinkel
03/31/2020, 6:06 PMreified T
diesieben07
03/31/2020, 6:07 PMdefaultProperty { null }
, without specifying the T
explicitly. So the compiler has to infer it from the arguments to defaultProperty
, which is just { null }
, which is of type () -> Nothing?
- T
is therefor inferred to be Nothing?
Sam Garfinkel
03/31/2020, 6:08 PMval foo: T
diesieben07
03/31/2020, 6:09 PMdiesieben07
03/31/2020, 6:09 PMSam Garfinkel
03/31/2020, 6:10 PM-Xnew-inference
although it doesn’t seem to help.diesieben07
03/31/2020, 6:10 PMSam Garfinkel
03/31/2020, 6:11 PM