Android 외 개발

kotlin use example

Spring-봄 2019. 12. 10. 13:44

변경 전

        val cursor: Cursor = readableDatabase.rawQuery(sql, null)
        while (cursor.moveToNext()) {

        }
        cursor.close()

변경 후

        readableDatabase.rawQuery(sql, null)?.use {
            while (it.moveToNext()){

            }
        }

 

https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/use.html

 

use - Kotlin Programming Language

 

kotlinlang.org

 

 

저작자표시 비영리 (새창열림)