https://kotlinlang.org logo
Title
t

tipsy

06/09/2018, 9:35 AM
is there any reason to prefer null over empty collection as return value in kotlin?
1
l

lex

06/09/2018, 9:39 AM
I think it is not specific for any language, it is related for business logic
typical solution is return empty collection for collections and null for value
d

diesieben07

06/09/2018, 9:47 AM
There are situations where both
null
and "empty collection" can be useful values, e.g.
null
meaning "not initialized yet" and "empty collection" meaning "initialized, but empty".
💯 1
l

lex

06/09/2018, 9:50 AM
yes, null for collections as "not initialized" can be (and should be) for domain object properties, but for business logic results (data, returned from services, etc) should be empty collection
4