Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin generate generic java code

I have an interface in kotlin, which looks something like this

interface BaseDao<in M : Model> {

    ...

    @Delete
    fun delete(models: Collection<M>)

    ...

}

Now when I look at the generated code I see something like this:

public interface BaseDao {

    ...

    @Delete
    void delete(@NotNull Collection var1);

    ...

}

Is there a way to tell kotlin that I want the type of the collection explicitly set?


1 Answers

The 'generated code' is actually compiled byte-code decompiled to Java. And since generic types are lost due to type erasure, you will see plain Collection.

When working with the code from Java, the function still enforces the correct types.

like image 103
nhaarman Avatar answered Apr 18 '26 06:04

nhaarman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!