Kotlin needs try-with-resources

Wow, that's a great idea that even beats most built in constructs that adresses this kind of issues. Your idea even allows for conditional creation of closable resources which is much harder with most common using/try-with-resources constructs, e.g.:

using {   val resource = if (isLocalhost()) {   ClosableResourceA().autoClose()   } else {   ClosableResourceB().autoClose()   }   ...

}

1 Like