java - "Return type of ... is not a subtype of the return type of the overridden member"?

标签 java android kotlin

我正在尝试对一个函数 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/

相关文章:

java - 从 Java 在 Oracle 数据库中创建表

java - 在后台初始化 Java Swing

java - 如何在 java jsch channelsftp setPermission(int permission, String path) 中设置 chmod 权限

android - 我们可以在 Android 中使用 SOAP UI 与客户端和服务器通信吗?

android - 如何在android中创建应用程序本地化?

java - Spring Boot-摆脱Hikari数据源并使用H2

android - 如何为android中 fragment 中的按钮设置onclick监听器

kotlin - 如何让 Kotlin 编译器将警告视为错误?

android - 我无法在 fragment 中使用 kotlin 定义 supportFragmentManager

android - 在 RecyclerView 中处理 EditText 的导航