title: How to use extension functions as TypeConverter methods for a Room database?
body: <p>I was wondering if anyone found a way to use kotlins extension functions as <code>TypeConverter</code> methods when using Room database. The code looks super clean, but I've not been able to find a way to add the converter to <code>RoomDatabase</code>s array of converters:</p>
  
  <pre><code>enum class Status(val code: Int) {
      ACTIVE(0), INACTIVE(1), COMPLETED(2)
  }
  
  @TypeConverter
  fun Status.toInt() : Int = this.code // This could be shorter I know
  
  @TypeConverter
  fun Int.toStatus() : Status = when(this) { // This could also be shorter
      Status.ACTIVE.code -&gt; Status.ACTIVE
      Status.INACTIVE.code -&gt; Status.INACTIVE
      Status.COMPLETED.code -&gt; Status.COMPLETED
      else -&gt; {
          Timber.e("Could not recognize Status")
          throw IllegalArgumentException("Could not recognize Status")
      }
  }
  </code></pre>
  
  <p>Even the tests look super elegant:</p>
  
  <pre><code>class SampleConverterTest {
  
      @Test
      fun fromIntToActiveStatus() {
          assertThat(Status.ACTIVE.toInt(), `is`(Status.ACTIVE.code))
      }
  
      @Test
      fun fromIntToInactiveStatus() {
          assertThat(Status.INACTIVE.toInt(), `is`(Status.INACTIVE.code))
      }
  
      @Test
      fun fromIntToCompletedStatus() {
          assertThat(Status.COMPLETED.toInt(), `is`(Status.COMPLETED.code))
      }
  
      @Test
      fun fromActiveStatusToInt() {
          assertThat(Status.ACTIVE.fromInt(), `is`(Status.ACTIVE))
      }
  
      @Test
      fun fromInactiveStatusToInt() {
          assertThat(Status.INACTIVE.fromInt(), `is`(Status.INACTIVE))
      }
  
      @Test
      fun fromCompletedStatusToInt() {
          assertThat(Status.COMPLETED.fromInt(), `is`(Status.COMPLETED))
      }
  }
  </code></pre>
  
  <p>I'm not super familiar with java kotlin interop, but is there any way to have these extensions as your <code>TypeConverters</code>?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Beware as @Luksprog pointed out in his answer, the <code>Status.fromInt()</code> extension method isn't a correct converter method. It would instead have to be an extension on <code>Int</code>. I've edited my question to show this.</p>