when class implements both interfaces? Implementation for AutoClosable is more simple and efficient.
k
kingsley
08/31/2017, 3:57 PM
Since it’s statically dispatched. This should work:
Copy code
(someCloseable as AutoClosable).use {}
b
beholder
08/31/2017, 4:18 PM
@kingsley, yes, I tried that, but it's rather ugly
k
kingsley
08/31/2017, 4:33 PM
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 🙂