https://kotlinlang.org logo
Title
d

damian

12/14/2017, 3:20 PM
@Andreas Sinz using
when
on an instance of
SpecificExceptions
the auto-completion for all branches at least doesn’t work
a

Andreas Sinz

12/14/2017, 3:24 PM
@damian with all branches you mean
ErrorOne
and
ErrorTwo
?
d

damian

12/14/2017, 3:24 PM
yes, it’s only giving me
ErrorTwo
as possibility
a

Andreas Sinz

12/14/2017, 3:25 PM
if you have an instance of
SpecificExcetpions
, it cannot be an instance of
ErrorOne
?
d

damian

12/14/2017, 3:26 PM
at least thats what the auto-completion of the
when
branches is telling me; also red-underine with “incompatible types”
a

Andreas Sinz

12/14/2017, 3:27 PM
but its not possible with ordinary classes too?
d

damian

12/14/2017, 3:28 PM
what do you mean?
a

Andreas Sinz

12/14/2017, 3:28 PM
ErrorOne
is not a subclass of
SpecificExceptions
, so an instance of
SpecificExceptions
can not be
ErrorOne
d

damian

12/14/2017, 3:29 PM
yes that is true. that’s why i was thinking / asking if there’s a way to extend sealed classes, or to inherit the collection of classes in a sealed class and add new ones in another class
a

Andreas Sinz

12/14/2017, 3:34 PM
Extending sealed classes is not possible, because that would make sealed classes useless
you could create something like
class SpecificBaseException(val exception: BaseException)
d

damian

12/14/2017, 4:28 PM
hmm. i’ll see if i can make it work for my use-case. thanks