https://kotlinlang.org logo
#getting-started
Title
# getting-started
v

v79

09/22/2023, 5:30 PM
Is it possible to combine multiple
is
cases in a
when
block over a sealed class? I was hoping for
when(sqsMessageBody) { is SqsMsgBody.Page, <http://SqsMsgBody.Post|SqsMsgBody.Post> -> { ... } }
but IntelliJ complains that they are incompatible types. I understand why, but in my case the differences between Page and Post are irrelevant here. I'm actually just trying to avoid a catch-all
else ->
clause...
e

ephemient

09/22/2023, 5:33 PM
do you mean
is SqsMsgBody.Page, is <http://SqsMsgBody.Post|SqsMsgBody.Post> ->
(with the extra
is
)?
👍 1
as it is, you're comparing
sqsMessageBody
with the
<http://SqsMsgBody.Post|SqsMsgBody.Post>
companion object, assuming it's not an object to begin with
v

v79

09/22/2023, 5:51 PM
Yes, that's what I was looking for, thank you.