Search code examples
kotlinsugarorm

Sugar ORM, List all in Kotlin? Java works, but Kotlin does not


The following Java code seems to be fine (no IDE errors),

List<Job> jobs = Job.listAll(Job.class);

When I copy-and-pasted, it was translated into,

val jobs = Job.listAll<Job>(Job::class.java)

But there was an error. Unresolved reference; listAll. What is the correct Kotlin equivalent?

The data class

import com.orm.SugarRecord

class Job : SugarRecord()
{

Sugar ORM: https://github.com/chennaione/sugar


Solution

  • This does not work because child class in Kotlin does not inherit static method from parent. (static does not exist in Kotlin)

    You call the method like this:

    SugarRecord.listAll(Job::class.java)