Is it possible to compiler choose `AutoClosable.us...
# stdlib
b
Is it possible to compiler choose
AutoClosable.use()
instead of
Closable.use()
when class implements both interfaces? Implementation for AutoClosable is more simple and efficient.
k
Since it’s statically dispatched. This should work:
Copy code
(someCloseable as AutoClosable).use {}
b
@kingsley, yes, I tried that, but it's rather ugly
k
Well. That’s about the option that you have. You could also do this:
Copy code
val foo: AutoCloseable =someCloseable
foo.use {}
I don’t really see a reason for picking one over the other anyway. Simple and efficient doesn’t sound compelling. If you are very concerned about the implementation detail, you can always make your own extension function 🙂