Hi guys, I'm facing a dilemma and I need your advi...
# announcements
w
Hi guys, I'm facing a dilemma and I need your advice. Which one of these two lines you think is better:
val parsedValue = if (propertyValue is String) propertyValue.toDouble() else propertyValue as Double
VS
val parsedValue = (propertyValue as? String)?.toDouble() ?: propertyValue as Double
s
first
1
but what type is
propertyValue
even
w
@Shawn any reason why you think it's better ?
s
looking at the statements in a vacuum I like the first better because it’s much clearer what’s happening
💯 1
w
@Shawn
propertyValue
is Any
s
are you okay with that potential ClassCastException lying in wait lol
w
yes I'm ok with that potential ClassCastException that can come from
as Double
m
Agree with Shawn. The second one takes a lot of 'processing' to figure out what is going on. The first is obvious.
👍 2