You were getting error because listOf(1, 2, null, 4) creates List<Int?>
, and in your second line, the returning collection from .filter{ it != null}
will also be typeof List<Int?>
. Answered for somebody else in future
You were getting error because listOf(1, 2, null, 4) creates List<Int?>
, and in your second line, the returning collection from .filter{ it != null}
will also be typeof List<Int?>
. Answered for somebody else in future