Very curious to know what techniques Kotliners use...
# announcements
n
Very curious to know what techniques Kotliners use for managing resources. In the example below I manage a resource via the Closable technique:
Copy code
interface Closable {
  val isClosed: Boolean

  fun close()
}

class ResourceX : Closable {
  val isClosed: Boolean
    get() = _isClosed
  private var _isClosed = false

  fun close() {
    if (!_isClosed) {
      // Do cleanup here.
      _isClosed = true
    }
  }

  fun operation() {
    if (_isClosed) throw IllegalStateException("ResourceX is closed")
    // Do stuff related to the operation here.
  }
}
n
Do note that the Kotlin Native Standard library doesn't have the
Closable
and
AutoClosable
interfaces.
e