Hi Guys, So if i have a type parameter, is there ...
# announcements
t
Hi Guys, So if i have a type parameter, is there no way to say that it can be “Any” except “Exception” ?
v
tvede: not directly.
Any
is just too broad.
As a workaround you can create an overload with
T: Exception
which throws on calling
t
Thanks,was afraid I overlooked something. Well the idea is that, when modeling results (which are either good or bad), then having a unified construct, could be a good idea, but not being able to say “exceptions are not good results” (i know this can depend on the type of thing you are modeling). 😛
v
(btw that above was to the wrong thread 😂)
Your case is easily solvable with strong typing
Copy code
sealed class Result {
    class Good(val result: Any)
    class Bad(val exs: Exception)
}
Now you write functions for
Result.Good