jvm signature 属性,意外覆盖:以下声明具有相同的JVM签名

I'm getting this error in Kotlin in this part:

class GitHubRepoAdapter(private val context: Context,

private val values: List) : ArrayAdapter(context, R.layout.list_item,

values) {

private val context: Context

in log it says:

Error:(14, 25) Accidental override: The following declarations have

the same JVM signature (getContext()Landroid/content/Context;):

fun (): Context

fun getContext(): Context!

I'm not able to see what is causing the problem.

解决方案

This happens because the Kotlin compiler tries to generate a getter for val context declared in your class primary constructor, namely a method getContext(), but the base class ArrayAdapter already has such a method.

You can solve that by doing one of the following:

Change your class' constructor parameter not to be a val.

class GitHubRepoAdapter(context: Context, ...

In this case, the getter won't be generated, and the conflict will be gone.

This seems to be the preferrable solution in your case, because, even without redeclaration, there is already a synthetic property context inferred from the Java getter.

class GitHubRepoAdapter(@get:JvmName("getContext_") private val context: Context, ...

This will make the compiler generate the getter with another JVM name (the one specified in the annotation), thus avoiding the conflict, but making accessing it from Java less intuitive (especially since there will be two similar functions). In Kotlin, you will still be able to use the property with its original name context.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值