https://kotlinlang.org logo
Title
d

David Glasser

05/15/2023, 11:01 PM
Let's say I have a class FooError that implements a bunch of different interfaces. I can't write a generic that uses FooError as a lower bound somehow, can I? Like I'd love to be able to do
inline fun <R> runFOrReturnFooError(f: () -> R): R = 
  if (someCondition) {
    f()
  } else {
    FooError()
  }
such that R is allowed to be any of the interfaces that FooError implements
r

Raphael TEYSSANDIER

05/15/2023, 11:40 PM
Does
inline fun <R : FooError> runFOrReturnFooError(f: () -> R): R
work ?
s

sciack

05/16/2023, 10:27 AM
Why not use a
Result
class?
I think you have to define as
<R: in FooError>
but not sure if works well.
also because with
where
condition all must match.