我正在尝试对一个函数 ActionableNotification.java
进行子类化,其内容类似于:
package com.venmo.notifications.notifications;
import android.content.ContextWrapper;
import com.squareup.picasso.Target;
public abstract class ActionableNotification extends ContextWrapper implements Target {
@NonNull
protected abstract String getTrackingNotificationCategory();
// ...
}
继承类的读法与此类似
class DeclineInsufficientFundsBalanceOnlyCardNotification(context : Context, intent : Intent) : ActionableNotification(context, intent) {
override fun getTrackingNotificationCategory() = ""
// ...
}
但是,当我尝试编译时出现此错误:
/Users/kupeek/dev/venmo-android/p2p-app/src/main/java/com/venmo/notifications/notifications/DeclineInsufficientFundsBalanceOnlyCardNotification.kt: (21, 53): Return type of 'getTrackingNotificationCategory' is not a subtype of the return type of the overridden member '@NonNull protected/protected and package/ abstract fun getTrackingNotificationCategory(): String defined in com.venmo.notifications.notifications.ActionableNotification'
我不明白这个错误信息,因为Kotlin继承类的返回类型是字符串,基类也是如此?
最佳答案
也许用 JetBrains 注解 @NotNull
来注解抽象方法会更好。我发现它看了一下this 。希望这可以帮助您。
关于java - "Return type of ... is not a subtype of the return type of the overridden member"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54522606/