Can a `Closeable` and/or `AutoCloseable` interface...
# stdlib
d
Can a
Closeable
and/or
AutoCloseable
interface be added to the standard library?
s
they are both part of the java stdlib already
d
I meant the multi-platform stdlib.
e
What for? We don’t have any classes in multi-platform stdlib that would implement them
d
Would be nice to have on the Native back-end.
e
You can have them in your own multi-platform library, though
But what for? Native stdlib does not have any things where implementing those interfaces would have made sense either
In particular, native stdlib does not currently have any files API.
d
Yeah, I guess nothing in the stdlib would use it but how about a standard way of releasing resources?
e
You can use Posix or Win32 APIs to work with files and you don’t need closeable for them
d
Not for files but like a wrappers for OpenGL objects, UI objects, etc.
e
Kotlin does not have any standard APIs to work with resources and does not define any resources in its common standard library. All resource-working API are for JVM only and are based on JVM resource-management designs
d
Oh okay then. That makes sense.
e
You are free do define your own DSL for working with your resources in your app. Kotlin provides quite rich facilities for that. For example, Kotlin/Native have some nice DSL for working with native memory resources
u
So if in the future we have 3rd party mp io, mp databases, ... Every framework will have it's own closeables and it's own implementation of use-alike dsl?
💯 1
e
I’d say let us see. If there emerges some predominantly common pattern, then it can be added to the standard library or even to the language in the future.