The problem has nothing to do with try-with resources and is simply an incompatible dependency problem between compiled code and the runtime.
SQLiteDatabase Closeable, , . .
/, , , , JVM. Kotlin , , , Closeable. :
inline fun <T : Closeable, R> T.use(block: (T) -> R): R { ... }
, writableDatabase ( -):
CHECKCAST java/io/Closeable
, SQLiteDatabase Closeable . Android, , . - . , , JAR JVM , . Android JAR.
, ? - use SQLiteDatabase, close ( Kotlin stdlib use):
inline fun <T : SQLiteDatabase, R> T.use(block: (T) -> R): R {
var closed = false
try {
return block(this)
} catch (e: Exception) {
closed = true
try {
close()
} catch (closeException: Exception) {
}
throw e
} finally {
if (!closed) {
close()
}
}
}
CHECKCAST android/database/sqlite/SQLiteDatabase, .