1

I've started to convert some of my code from Java to Kotlin.

Some of these are database schema classes, containing constants for the different column names (I'm working with Android here).

I've modified my Java final class with static constants, so that it is an object in Kotlin with constants (const):

object MySchema : BaseColumns {

    const val TABLE_NAME = "my_table"
    const val COL_TITLE = "title"
    const val COL_DETAIL = "detail"
    // ...

}

The BaseColumns class in Android is basically this:

public interface BaseColumns {

    public static final String _ID = "_id";

    public static final String _COUNT = "_count";
}

However, this code now does not compile:

// ContentValues values = ...
values.put(MySchema._ID, myThing.getId())

Unresolved reference: _ID

This doesn't make sense to me since MySchema implements the BaseColumns interface, and thus should inherit its fields.

The code that isn't compiling was able to compile before I had converted the database schema class to Kotlin - i.e.:

public final class MySchema implements BaseColumns {

    // ...

}

I hope that makes sense.

What am I doing wrong here?

Farbod Salamat-Zadeh
  • 19,687
  • 20
  • 75
  • 125

0 Answers0