简体   繁体   English

“'Mapper' 中的 map(From)' 与 'CursorToMessageImpl' 中的 'map(Object)' 冲突;两种方法具有相同的擦除,但都不会覆盖另一个

[英]"map(From)' in 'Mapper' clashes with 'map(Object)' in 'CursorToMessageImpl'; both methods have same erasure, yet neither overrides the other

This is code in kotlin.这是 kotlin 中的代码。 Showing error Type inference failed: inline fun T.apply(block: T.() -> Unit): T cannot be applied to receiver: Message arguments: (Message.() -> Any).显示错误类型推断失败:inline fun T.apply(block: T.() -> Unit): T 无法应用于接收器:消息 arguments: (Message.() -> Any)。

**map(From)' in 'Mapper' clashes with 'map(Object)' in 'CursorToMessageImpl'; 'Mapper' 中的 **map(From)' 与 'CursorToMessageImpl' 中的 'map(Object)' 冲突; both methods have same erasure, yet neither overrides the other **两种方法都有相同的擦除,但都没有覆盖另一个**

class CursorToMessageImpl @Inject constructor(
private val context: Context,
private val cursorToPart: CursorToPart,
private val keys: KeyManager,
private val permissionManager: PermissionManager,
private val preferences: Preferences) : CursorToMessage
{
private val uri = Uri.parse("content://mms-sms/complete-conversations")
    private val projection = arrayOf(
            MmsSms.TYPE_DISCRIMINATOR_COLUMN,
            MmsSms._ID,
            Mms.DATE,
            Mms.DATE_SENT,
            Mms.READ,
            Mms.THREAD_ID,
            Mms.LOCKED,

            Sms.ADDRESS,
            Sms.BODY,
            Sms.SEEN,
            Sms.TYPE,
            Sms.STATUS,
            Sms.ERROR_CODE,

            Mms.SUBJECT,
            Mms.SUBJECT_CHARSET,
            Mms.SEEN,
            Mms.MESSAGE_TYPE,
            Mms.MESSAGE_BOX,
            Mms.DELIVERY_REPORT,
            Mms.READ_REPORT,
            MmsSms.PendingMessages.ERROR_TYPE,
            Mms.STATUS
    )

    override fun map(from: Pair<Cursor, CursorToMessage.MessageColumns>): Message {
        val cursor = from.first
        val columnsMap = from.second

        return Message().apply {
            type = when {
                cursor.getColumnIndex(MmsSms.TYPE_DISCRIMINATOR_COLUMN) != -1 -> cursor.getString(columnsMap.msgType)
                cursor.getColumnIndex(Mms.SUBJECT) != -1 -> "mms"
                cursor.getColumnIndex(Sms.ADDRESS) != -1 -> "sms"
                else -> "unknown"
            }

            id = keys.newId()
            threadId = cursor.getLong(columnsMap.threadId)
            contentId = cursor.getLong(columnsMap.msgId)
            date = cursor.getLong(columnsMap.date)
            dateSent = cursor.getLong(columnsMap.dateSent)
            read = cursor.getInt(columnsMap.read) != 0
            locked = cursor.getInt(columnsMap.locked) != 0
            subId = if (columnsMap.subId != -1) cursor.getInt(columnsMap.subId)

            else -1

            when (type) {
                "sms" -> {
                    address = cursor.getString(columnsMap.smsAddress) ?: ""
                    boxId = cursor.getInt(columnsMap.smsType)
                    seen = cursor.getInt(columnsMap.smsSeen) != 0

                    body = columnsMap.smsBody
                            .takeIf { column -> column != -1 } // The column may not be set
                            ?.let { column -> cursor.getString(column) } ?: "" // cursor.getString() may return null

                    errorCode = cursor.getInt(columnsMap.smsErrorCode)
                    deliveryStatus = cursor.getInt(columnsMap.smsStatus)
                }

                "mms" -> {
                    address = getMmsAddress(contentId)
                    boxId = cursor.getInt(columnsMap.mmsMessageBox)
                    date *= 1000L
                    dateSent *= 1000L
                    seen = cursor.getInt(columnsMap.mmsSeen) != 0
                    mmsDeliveryStatusString = cursor.getString(columnsMap.mmsDeliveryReport) ?: ""
                    errorType = if (columnsMap.mmsErrorType != -1) cursor.getInt(columnsMap.mmsErrorType) else 0
                    messageSize = 0
                    readReportString = cursor.getString(columnsMap.mmsReadReport) ?: ""
                    messageType = cursor.getInt(columnsMap.mmsMessageType)
                    mmsStatus = cursor.getInt(columnsMap.mmsStatus)
                    val subjectCharset = cursor.getInt(columnsMap.mmsSubjectCharset)
                    subject = cursor.getString(columnsMap.mmsSubject)
                            ?.takeIf { it.isNotBlank() }
                            ?.let(_root_ide_package_.app.google.android.mms.pdu_alt.PduPersister::getBytes)
                            ?.let { _root_ide_package_.app.google.android.mms.pdu_alt.EncodedStringValue(subjectCharset, it).string } ?: ""
                    textContentType = ""
                    attachmentType = Message.AttachmentType.NOT_LOADED

                    parts.addAll(cursorToPart.getPartsCursor(contentId)?.map { cursorToPart.map(it) } ?: listOf())
                }
                else -> -1
            }
        }
    }


**and interference mapper is :-**


interface Mapper<in From, out To> {

    fun map(from: From): To
}

I'm not 100% sure this is your issue, but since else -> -1 in your when statement doesn't accomplish anything, try removing it.我不是 100% 确定这是您的问题,但是由于else -> -1在您的when语句中没有完成任何事情,请尝试将其删除。 A when statement doesn't have to be exhaustive when it isn't being forced to be evaluated as an expression (by assigning its result to a variable or property).当不强制将 when 语句作为表达式求值时(通过将其结果分配给变量或属性) when语句不必是详尽无遗的。

else -> -1 at the bottom of your when statement causes it to be a when expression that returns Any . else -> -1在你的when语句的底部使它成为一个返回Anywhen表达式 Usually, the compiler can interpret a lambda ending in an expression other than Unit as having an implicit return of Unit if there are no overloads that it would otherwise match.通常,编译器可以将 lambda 以除 Unit 以外的表达式结尾的表达式解释为具有Unit的隐式返回,如果没有其他情况下会匹配的重载。 But there may be some cases where the involved classes are complex enough to prevent it from deducing that.但是在某些情况下,所涉及的类足够复杂,无法推断出这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 两种方法具有相同的擦除,但是都不能覆盖另一种方法 - Both methods have same erasure, yet neither overrides the other 两种方法都有相同的擦除,但都没有覆盖另一个 - Both methods have same erasure yet neither overrides the other 在实现ConsumerSeekAware接口时,如何使“这两种方法都具有相同的擦除能力,但两者都不能覆盖另一个方法”的警告静音? - How do I silence the “both methods have same erasure yet neither overrides the other” warning while implementing the ConsumerSeekAware interface? 集具有相同的擦除,但没有一个覆盖另一个错误 - Set have the same erasure, yet neither overrides the other error 无法覆盖onBeforeConvert:“......有相同的删除,但都没有覆盖其他” - Cannot Override onBeforeConvert: “…have the same erasure, yet neither overrides the other” SkuDetailsResponseListener() 中的“两种方法都具有相同的擦除功能,但都不会覆盖另一个”方法冲突错误 - 'Both methods have same erasure, yet neither overides the other' method clash error in SkuDetailsResponseListener() 实现Comparable,compareTo名称冲突:“具有相同的擦除,但不会覆盖其他” - Implementing Comparable, compareTo name clash: “have the same erasure, yet neither overrides the other” 名称冲突 - 具有相同的擦除但在方法参数generic中不会覆盖另一个 - Name clash - have the same erasure yet neither overrides the other in method parameter generic 具有相同的擦除,但不能覆盖仅在一种情况下出现的其他警告 - Have same erasure, yet neither overrides the other warning appearing in only ONE situation 界面和一个类。名称冲突:相同的擦除,但都不会覆盖其他 - interface and a class. name clash: same erasure, yet neither overrides other
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM