It’s kind of the same reason that Kotlin doesn’t have lazy
as a language feature, or async await as keywords. Kotlin tries to bake in generic features that can then be used to create syntax-y features that aren’t actually part of the language, which basically opens up the opportunity for many different and interesting structurces and paradigms. With higher order functions and contracts, you can perfectly emulate try with resources. Contracts are indeed experimental, but their range is going to be quite wide, that’s why they are experimental. The current version of them works quite well, with a few rough edges. Coroutines were once experimental, but they very quickly became stable. Contracts have got a ton of use cases that would allow you to make more interesting constructs and complex management schemes than just a plain old try with resources or using block that most languages have. Simply, Kotlin is trying to give you a superset of whatever features you need, and then either create by themselves or let the community create a lot of specific features using it. Tbh, I’d prefer more powerful contracts that would let me have the same features that a try with resources or using block would have in other languages cuz then taht also means that I can make more constructs that are specific to my use case (i.e. basically create a flavor of the language depending on whatever domain I am in.) That’s why there’s also a lot of other DSL features that are really generic.
Kotlin is not per se against having it. They’re against implementing specific features and instead opt in for broader features that will give you the same fluency and more. That’s why there are also discussions with the Result
type for example about expanding the meaning of the safe navigation operator ?.
because it was originally a rather specific features that only deals with nulls, but it could probably be used for wider use cases that guarantee safety and basically communicate the idea of right-biased datatypes (like Either
s and the like)