title: Kotlin Closable and SQLiteDatabase on Android
body: <p>I use this code in my project</p>
  
  <pre><code>fun getAllData(): List&lt;Data&gt; = writableDatabase.use { db -&gt;
      db.query(...)
  }
  </code></pre>
  
  <p>It executes successfully on Lollipop devices, but on pre-Lollipop it throws a ClassCastException</p>
  
  <pre><code>FATAL EXCEPTION: main
  java.lang.ClassCastException: android.database.sqlite.SQLiteDatabase cannot be cast to java.io.Closeable
  </code></pre>
  
  <p>Probably because it's Java 1.6 and doesn't have the try-with-resources feature, but I'm not sure.</p>
  
  <p>So why do I have this exception and how can it be fixed?</p>