is it possible to concatenate elvis operators? for...
# android
p
is it possible to concatenate elvis operators? for example, this doesn't give compile error:
Copy code
fontSize = spTextSize ?: oldTextSize ?: 0.sp,
is anything wrong with it? my intention is that if spTextSize is null, set oldTextSize, but if oldTextSize is null too, then set 0.sp
c
Works on the playground. Get sure that all types are the same. https://pl.kotl.in/wXTjQmI3T
p
yes, it works, the issue here is that I can't find anything about this in the official kotlin documentation
and I'm afraid as this is not documented, maybe I'll stop working or change behaviour at any moment
g
It's fine, it's how all operators work, they applied from left to right
If you want, you may rely on Kotlin language specification https://kotlinlang.org/spec/syntax-and-grammar.html#grammar-rule-elvisExpression
p
thank you Andrey
m
This will work, no issue with this. Very common in use cases like yours.