Kotlin, ORMLite and type inference


#1

Good day! I'm writing some android app using Kotlin and ORMLite. I have some basic Model trait and all my models implement it. I have a list with my model classes. I want to create all database tables for all my model classes using ORMLite:

 
for (clazz in modelClasses) {
    TableUtils.createTable(connectionSource, clazz)
}

clazz is Class<out Model>, TableUtils.createTable() is

 
public static <T> int createTable(ConnectionSource connectionSource, Class<T> dataClass) {...}

but still I get this error:

Error:(46, 24) Gradle: None of the following functions can be called with the arguments supplied: public open fun <T> createTable(connectionSource: com.j256.ormlite.support.ConnectionSource!, dataClass: java.lang.Class<(???..???)>!): kotlin.Int defined in com.j256.ormlite.table.TableUtils public open fun <T> createTable(connectionSource: com.j256.ormlite.support.ConnectionSource!, tableConfig: com.j256.ormlite.table.DatabaseTableConfig<(???..???)>!): kotlin.Int defined in com.j256.ormlite.table.TableUtils

I can explicitly provide T like

TableUtils.createTable<Model>(connectionSource, clazz)

but all is the same. Maybe I'm missing something obvious here?


#2

Hi Vladimir!

It's a bug. The 'out' projections are not fully supported in type inference yet. For a current workaround please write

``

TableUtils.createTable(connectionSource, clazz as Class<Model>)

I’ve added your example to tests already, so no need to create a separate issue for it.
Thank you.


#3

Thank you, Svetlana! Could you give me the issue id so I can watch the progress?


#4

https://youtrack.jetbrains.com/issue/KT-2570


#5

Thanks again, Svetlana!