https://kotlinlang.org logo
Title
t

thana

02/25/2019, 1:34 PM
is it possible to write a contract where somthing implies, that a method will not return
null
? (all examples i can find implie the other way round)
l

LeoColman

02/25/2019, 1:36 PM
I think that if by design your method can either be nullable or no-nullable, depending on a variable
Maybe your design is not correct, and you should refactor the two cases
t

thana

02/25/2019, 1:36 PM
damn, that would be far easier, thats right 😄
l

LeoColman

02/25/2019, 1:36 PM
Can you show us an example of what you're trying to do?
t

thana

02/25/2019, 1:37 PM
in fact you are just right - i should split it into two methods. you know that sitautions where you feel really stupid for not seeing the obvious? 😂
s

streetsofboston

02/25/2019, 1:40 PM
Oh... we've all been there, Malte! :-D
l

LeoColman

02/25/2019, 1:43 PM
And we'll be there many more times
Classic http://xyproblem.info/ perhaps?
t

thana

02/25/2019, 1:49 PM
na not really... the emssage has a boolean flag (which is bad on it's own, too), and when it's
false
it will return a non-null value - always. i knew this smeels before, but then i saw a colleague using it, and he had to use
?.
all over the place and i though "hey this is kotlin! it has a cool feature that might solve this problem" and didn't realise it would be much easier to simply split the method into two
so... maybe.. it's excactly the problem 🤷
l

LeoColman

02/25/2019, 1:56 PM
I like how Kotlin makes some code smells even more smelly hahaha
😁 1
t

thana

02/25/2019, 1:59 PM
😄